-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
45 lines (36 loc) · 831 Bytes
/
example_test.go
File metadata and controls
45 lines (36 loc) · 831 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
35
36
37
38
39
40
41
42
43
44
45
package main_test
import (
"fmt"
"github.com/sonalys/gon"
)
func Example_featureFlag() {
scope, err := gon.
NewScope().
WithValues(gon.Values{})
if err != nil {
panic(err)
}
rateLimitPolicy := gon.If(gon.Exists("optionalConnector"), gon.Reference("optionalConnector.premiumLimit"), gon.Literal(10))
rateLimit, err := scope.Compute(rateLimitPolicy)
if err != nil {
panic(err)
}
fmt.Printf("\n\nBefore: %d", rateLimit)
type premiumMembership struct {
RateLimit int `gon:"premiumLimit"`
}
scope, err = scope.WithValues(gon.Values{
"optionalConnector": gon.Literal(premiumMembership{RateLimit: 500}),
})
if err != nil {
panic(err)
}
rateLimit, err = scope.Compute(rateLimitPolicy)
if err != nil {
panic(err)
}
fmt.Printf("\nAfter: %d", rateLimit)
//Output:
// Before: 10
// After: 500
}