Hi Team , I am trying to setup growthbook feature ...
# announcements
g
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
Hi Mounica - are you setting any user attributes?
oh, "Key"
g
Yes, key is the only attribute we're using
f
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
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
in the code you posted, you have:
Copy code
WithAttributes(growthbook.Attributes{
                "Key": ID,
            })
are you sure have "linkID"?
g
Yes, I just changed it before I shared the code
f
okay
the code looks right, can you debug what the linkID is being set to?
g
Yes, it's being set to the correct value
f
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
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
huh, that seems like that should be working
can you open an issue on the golang repo with your sample code?
g
yes sure. will do that
f
thanks!