11package featuregate
22
3- import (
4- "encoding/json"
5-
6- "github.com/google/uuid"
7- "github.com/samber/lo"
8- )
9-
10- type Org interface {
11- Context
12-
13- ID () * uuid.UUID
14- PortalID () * uuid.UUID
15- OrgName () * string
16- FeatureSet () * string
17- Tier () * string
18- }
19-
20- type Context interface {
21- Key () string
22- Kind () string
23- Anonymous () bool
24- GetCustomAttributes () map [string ]any
25- AddCustomAttribute (name string , value any )
26- }
27-
283type Gate interface {
29- EvaluateBool (flag string , defaultValue bool ) (bool , error )
30- EvaluateInt (flag string , defaultValue int ) (int , error )
31- EvaluateFloat64 (flag string , defaultValue float64 ) (float64 , error )
32- EvaluateString (flag string , defaultValue string ) (string , error )
33- EvaluateJSON (flag string , defaultValue json.RawMessage ) (json.RawMessage , error )
34-
35- WithOrg (org Org ) (Gate , error )
36- WithFFContext (custom ... Context ) (Gate , error )
4+ EvaluateBool (namespace , flag string , defaultValue bool ) (bool , error )
375}
386
397func NewNoop () Gate {
@@ -42,72 +10,6 @@ func NewNoop() Gate {
4210
4311type Noop struct {}
4412
45- func (n Noop ) EvaluateBool (string , bool ) (bool , error ) {
13+ func (n Noop ) EvaluateBool (string , string , bool ) (bool , error ) {
4614 return true , nil
4715}
48-
49- func (n Noop ) EvaluateInt (string , int ) (int , error ) {
50- return 0 , nil
51- }
52-
53- func (n Noop ) EvaluateFloat64 (string , float64 ) (float64 , error ) {
54- return 0 , nil
55- }
56-
57- func (n Noop ) EvaluateString (string , string ) (string , error ) {
58- return "" , nil
59- }
60-
61- func (n Noop ) EvaluateJSON (string , json.RawMessage ) (json.RawMessage , error ) {
62- return json .RawMessage (`{}` ), nil
63- }
64-
65- func (n Noop ) WithFFContext (custom ... Context ) (Gate , error ) {
66- return Noop {}, nil
67- }
68-
69- func (n Noop ) WithOrg (org Org ) (Gate , error ) {
70- return n .WithFFContext (org )
71- }
72-
73- type NamespaceOrg string
74-
75- var _ Org = NamespaceOrg ("" )
76-
77- func (n NamespaceOrg ) AddCustomAttribute (name string , value any ) {}
78-
79- func (n NamespaceOrg ) Anonymous () bool {
80- return false
81- }
82-
83- func (n NamespaceOrg ) FeatureSet () * string {
84- return nil
85- }
86-
87- func (n NamespaceOrg ) GetCustomAttributes () map [string ]any {
88- return nil
89- }
90-
91- func (n NamespaceOrg ) ID () * uuid.UUID {
92- return lo .ToPtr (uuid .NewSHA1 (uuid .NameSpaceURL , []byte (n )))
93- }
94-
95- func (n NamespaceOrg ) Key () string {
96- return string (n )
97- }
98-
99- func (n NamespaceOrg ) Kind () string {
100- return "namespace"
101- }
102-
103- func (n NamespaceOrg ) OrgName () * string {
104- return lo .ToPtr (string (n ))
105- }
106-
107- func (n NamespaceOrg ) PortalID () * uuid.UUID {
108- return n .ID ()
109- }
110-
111- func (n NamespaceOrg ) Tier () * string {
112- return nil
113- }
0 commit comments