You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first block of code above, using the FindFlags returns the same flag. However, the object returned does not have its Variants field populated when used with FindFlags (but it is populated with GetFlag)
Possible Solution
Steps to Reproduce (for bugs)
The following main.go file, when run will error out in FlagByName with the error:
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
main.FlagByName()
.../main.go:51 +0x464
main.main()
.../main.go:9 +0x37
Debugger finished with exit code 0
If you comment out the call to FlagByName, it will succeed (and the code after flag := flags[0] is identical between the two)
package main
import (
"github.com/antihax/optional"
"github.com/checkr/goflagr"
)
func main() {
FlagByName()
flagrConfig := goflagr.NewConfiguration()
flagrConfig.BasePath = "http://localhost:8080/api/v1"
apiClient := goflagr.NewAPIClient(flagrConfig)
myFlagEnabled := ""
flag, _, err := apiClient.FlagApi.GetFlag(nil, 3)
if err != nil{
// Default to a reasonable default in case Flagr is down
myFlagEnabled = "false"
} else {
myVariant := flag.Variants[0]
myAttachment := (*myVariant.Attachment).(map[string]interface {})
myFlagEnabled = myAttachment["value"].(string)
}
if myFlagEnabled == "true"{
doMyNewThing()
} else {
doMyOldThing()
}
}
func FlagByName(){
flagrConfig := goflagr.NewConfiguration()
flagrConfig.BasePath = "http://localhost:8080/api/v1"
apiClient := goflagr.NewAPIClient(flagrConfig)
ffo := goflagr.FindFlagsOpts{
Key: optional.NewString("my_test_flag"),
}
flags, _, err := apiClient.FlagApi.FindFlags(nil, &ffo)
flag := flags[0]
myFlagEnabled := ""
if err != nil{
// Default to a reasonable default in case Flagr is down
myFlagEnabled = "false"
} else {
myVariant := flag.Variants[0]
myAttachment := (*myVariant.Attachment).(map[string]interface {})
myFlagEnabled = myAttachment["value"].(string)
}
if myFlagEnabled == "true"{
doMyNewThing()
} else {
doMyOldThing()
}
}
func doMyNewThing(){
return
}
func doMyOldThing(){
return
}
Context
Your Environment
Version used (flagr version): Current available docker container on checkr/flagr; postgres RDS backend
Server type and version: running as an AWS ECS Fargate deploy
Operating System and version (uname -a):
Link to your project:
The text was updated successfully, but these errors were encountered:
Hey, please use the preload query param for findFlags, because preloading flags with variants and segments are expensive, thus we didn't include it in findFlags by default.
Expected Behavior
What should happen:
In
go
, the following two blocks of code should setflag
to be an identical objectCurrent Behavior
The first block of code above, using the
FindFlags
returns the same flag. However, the object returned does not have itsVariants
field populated when used with FindFlags (but it is populated with GetFlag)Possible Solution
Steps to Reproduce (for bugs)
The following
main.go
file, when run will error out inFlagByName
with the error:If you comment out the call to FlagByName, it will succeed (and the code after
flag := flags[0]
is identical between the two)Context
Your Environment
flagr version
): Current available docker container oncheckr/flagr
; postgres RDS backenduname -a
):The text was updated successfully, but these errors were encountered: