Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ func (d *configBase) GetNumber(key string, fallback float64) float64 {
return fallback
}

// Gets the int64 value at the given key in the DynamicConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think all these comments are out of date now that there is layer, and these utils exist on both types. Mind fixing that up?

// Returns the fallback int64 if the item at the given key is not found or not of type int64
func (d *configBase) GetInt(key string, fallback int64) int64 {
if v, ok := d.Value[key]; ok {
switch val := v.(type) {
case int64:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we cast other numeric types to int64? What does json give us? @daniel-statsig noticed in other SDKs that json parsing gives you only a certain set of types - does json parsing in go give an int64?

logExposure(d, key)
return val
}
}
return fallback
}

// Gets the boolean value at the given key in the DynamicConfig
// Returns the fallback boolean if the item at the given key is not found or not of type boolean
func (d *configBase) GetBool(key string, fallback bool) bool {
Expand Down
13 changes: 12 additions & 1 deletion types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func doValidation(t *testing.T, c *configBase) {
if c.GetBool("Object", false) {
t.Errorf("Failed to use fallback boolean")
}

if c.GetInt("String", 1) != 1 {
t.Errorf("Failed to use fallback int")
}
if c.GetInt("Number", 1) != 1 {
t.Errorf("Failed to use fallback int")
}
if c.GetInt("Int", 1) != 123 {
t.Errorf("Failed to return int")
}
}

func TestBasic(t *testing.T) {
Expand All @@ -57,7 +67,8 @@ func TestBasic(t *testing.T) {
"NestedBool": false,
"NestedNum": 37
},
"Array":[1,2,3]
"Array":[1,2,3],
"Int": 123
}`,
),
&jsonMap,
Expand Down