-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathutils.go
More file actions
34 lines (30 loc) · 818 Bytes
/
utils.go
File metadata and controls
34 lines (30 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package flagsmith
import (
"sort"
)
func mapIdentityEvaluationContextToTraits(ic IdentityEvaluationContext) []*Trait {
traits := make([]*Trait, len(ic.Traits))
for i, tKey := range sortedKeys(ic.Traits) {
traits[i] = mapTraitEvaluationContextToTrait(tKey, ic.Traits[tKey])
}
return traits
}
func mapTraitEvaluationContextToTrait(tKey string, tCtx *TraitEvaluationContext) *Trait {
if tCtx == nil {
return &Trait{TraitKey: tKey, TraitValue: nil}
}
if tCtx.Transient == nil {
return &Trait{TraitKey: tKey, TraitValue: tCtx.Value}
}
return &Trait{TraitKey: tKey, TraitValue: tCtx.Value, Transient: *tCtx.Transient}
}
func sortedKeys[Map ~map[string]V, V any](m Map) []string {
keys := make([]string, len(m))
i := 0
for tKey := range m {
keys[i] = tKey
i++
}
sort.Strings(keys)
return keys
}