https://www.growthbook.io/ logo
#announcements
Title
# announcements
g

gorgeous-angle-33742

05/16/2022, 6:29 AM
Hi Team , I am trying to setup growthbook feature in golang. I end up getting the default value irrespective of the split set. Any leads on how to fix this?
Copy code
b, _ := json.Marshal(jsonMap["features"])
features := growthbook.ParseFeatureMap(b)
contextGB := growthbook.NewContext().
	WithFeatures(features).
	WithAttributes(growthbook.Attributes{
                "Key": ID,
            })
gb := growthbook.New(contextGB)
if gb.Feature("backend_enable_digilocker").On {
            log.Println("FEATURE IS ON")
}
f

fresh-football-47124

05/16/2022, 6:31 AM
Hi Mounica - are you setting any user attributes?
oh, "Key"
g

gorgeous-angle-33742

05/16/2022, 6:31 AM
Yes, key is the only attribute we're using
f

fresh-football-47124

05/16/2022, 6:33 AM
you need to tell GrowthBook if you're using another attribute other than 'id' (or rename key to id)
by using the hashAttribute
oh, wait, perhaps not - one sec
can you share what the json file is?
g

gorgeous-angle-33742

05/16/2022, 6:43 AM
Copy code
"features": {
        "manual_upload_button_visibility": {
            "defaultValue": true,
            "rules": [
                {
                    "variations": [
                        true,
                        false
                    ],
                    "weights": [
                        0.5,
                        0.5
                    ],
                    "key": "manual_upload_button_visibility",
                    "hashAttribute": "linkID"
                }
            ]
        },
        "backend_enable_digilocker": {
            "defaultValue": false,
            "rules": [
                {
                    "variations": [
                        false,
                        true
                    ],
                    "weights": [
                        0.5,
                        0.5
                    ],
                    "hashAttribute": "linkID"
                }
            ]
        }
    }
linkID is the key we are using, it's added on growthbook dashboard as well. In code we are using linkID only
Copy code
WithAttributes(growthbook.Attributes{
                "linkID": ID,
            })
It's working fine on another project with JS, but I am not able to figure it out in golang
f

fresh-football-47124

05/16/2022, 6:48 AM
in the code you posted, you have:
Copy code
WithAttributes(growthbook.Attributes{
                "Key": ID,
            })
are you sure have "linkID"?
g

gorgeous-angle-33742

05/16/2022, 6:49 AM
Yes, I just changed it before I shared the code
f

fresh-football-47124

05/16/2022, 6:49 AM
okay
the code looks right, can you debug what the linkID is being set to?
g

gorgeous-angle-33742

05/16/2022, 6:58 AM
Yes, it's being set to the correct value
f

fresh-football-47124

05/16/2022, 6:59 AM
you might just be in the 'false' group
you could try changing the weights to 0.9 for 'true' to see if you can get put into the 'true' variation
g

gorgeous-angle-33742

05/16/2022, 7:00 AM
I did that as well..by setting true to 1 and 0 false , default false
even at that point, i still am getting false as the value i.e, getting default value all the time
f

fresh-football-47124

05/16/2022, 7:04 AM
huh, that seems like that should be working
can you open an issue on the golang repo with your sample code?
g

gorgeous-angle-33742

05/16/2022, 7:17 AM
yes sure. will do that
f

fresh-football-47124

05/16/2022, 7:21 AM
thanks!
44 Views