-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathgoff_context_specifics.go
50 lines (45 loc) · 1.49 KB
/
goff_context_specifics.go
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
46
47
48
49
50
package ffcontext
import "time"
type GoffContextSpecifics struct {
// CurrentDateTime is the current date time to use for the evaluation.
CurrentDateTime *time.Time `json:"currentDateTime"`
// FlagList is the list of flags to evaluate in a bulk evaluation.
FlagList []string `json:"flagList"`
// ExporterMetadata is the metadata to be used by the exporter.
ExporterMetadata map[string]interface{} `json:"exporterMetadata"`
}
// addCurrentDateTime adds the current date time to the context.
// This function formats the current date time to RFC3339 format.
func (g *GoffContextSpecifics) addCurrentDateTime(currentDateTime any) {
switch value := currentDateTime.(type) {
case *time.Time:
g.CurrentDateTime = value
case time.Time:
g.CurrentDateTime = &value
case string:
if currentDateTime, err := time.ParseInLocation(time.RFC3339, value, time.Local); err == nil {
g.CurrentDateTime = ¤tDateTime
}
return
default:
return
}
}
// addListFlags adds the list of flags to evaluate in a bulk evaluation.
func (g *GoffContextSpecifics) addListFlags(flagList any) {
if value, ok := flagList.([]string); ok {
g.FlagList = value
}
if value, ok := flagList.([]interface{}); ok {
for _, val := range value {
if valAsString, ok := val.(string); ok {
g.FlagList = append(g.FlagList, valAsString)
}
}
}
}
func (g *GoffContextSpecifics) addExporterMetadata(exporterMetadata any) {
if value, ok := exporterMetadata.(map[string]interface{}); ok {
g.ExporterMetadata = value
}
}