I’m using the Golang SDK to load an Experiment fro...
# ask-questions
i
I’m using the Golang SDK to load an Experiment from the API. However, it seems that the response Experiment model differs from the Experiment model in the SDK. For example, in the response model, there is a
phrase
field, which does not exist in the SDK model. The SDK model, on the other hand, has a
phrase
field of type string. Is this a problem, or am I using the wrong approach?
Oh, looks like phases represent the experiments by time range. So does SDK support getting the active phase? Or I have to check the dateStarted and dateEnded manually?
f
the dataStarted and dateEnded is not really relevant for the SDK
why I think you might be using the API rather than the SDK end point?
i
How to get experiment using SDK? I can’t find that in the docs
f
you can make an SDK from the GrowthBook UI
Screenshot 2023-10-19 at 11.54.16 PM.png
that will return the right data your Go SDK needs
i
Yes, I did it. But I still can not find the SDK function to get Experiment instance by the experiment key
- I created an experiment on UI - I expect that SDK has an function that return the Experiment to pass into the Run function
f
did you create it linked to a feature flag?
i
Do you mean I have to create a feature flag that link to the experiment then get the experiment by getting Feature from SDK?
f
There are a few ways to run experiments with Growthbook
you can do inline experiments, where you define the variations and weights in code
or you can use the feature flags
if the feature flag only has the experiment rule, than it will work essentially the same way as you are expecting it to
but you would evaluate the flag with the flag name, not the experiment name
the trackingCallback will be called with the experiment name either way
i
Oh, I got it. Thank you.
It seems like features map must be get manually using http request, right?
Im following the docs in SDK Configuration
f
I think you’re missing getting the feature value itself. So you need to do is call one of the eval or isOn methods.
a
If you set up your API key in the context, you can use the
LoadFeatures
method to get the features: https://pkg.go.dev/github.com/growthbook/growthbook-golang#GrowthBook.LoadFeatures