mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-15 09:30:12 -05:00
* add a GET /accounts/{a}/boostrap URI that delivers the same as GET /
but also mailboxes for a given account, in case the UI remembers the
last used account identifier, to avoid an additional roundtrip
* streamline the use of simpleError()
* add logging of errors at the calling site
* add logging of evictions of Sessions from the cache
* change default Session cache TTL to 5min instead of 30sec
44 lines
866 B
Go
44 lines
866 B
Go
// Package structs provides some utility functions for dealing with structs.
|
|
package structs
|
|
|
|
import (
|
|
"maps"
|
|
"slices"
|
|
|
|
orderedmap "github.com/wk8/go-ordered-map"
|
|
)
|
|
|
|
// CopyOrZeroValue returns a copy of s if s is not nil otherwise the zero value of T will be returned.
|
|
func CopyOrZeroValue[T any](s *T) *T {
|
|
cp := new(T)
|
|
if s != nil {
|
|
*cp = *s
|
|
}
|
|
return cp
|
|
}
|
|
|
|
// Returns a copy of an array with a unique set of elements.
|
|
//
|
|
// Element order is retained.
|
|
func Uniq[T comparable](source []T) []T {
|
|
m := orderedmap.New()
|
|
for _, v := range source {
|
|
m.Set(v, true)
|
|
}
|
|
set := make([]T, m.Len())
|
|
i := 0
|
|
for pair := m.Oldest(); pair != nil; pair = pair.Next() {
|
|
set[i] = pair.Key.(T)
|
|
i++
|
|
}
|
|
return set
|
|
}
|
|
|
|
func Keys[K comparable, V any](source map[K]V) []K {
|
|
if source == nil {
|
|
var zero []K
|
|
return zero
|
|
}
|
|
return slices.Collect(maps.Keys(source))
|
|
}
|