Skip to content

Instantly share code, notes, and snippets.

@asaschachar
Last active June 8, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaschachar/ae0de5b36a7f46211cfcc13636df468a to your computer and use it in GitHub Desktop.
Save asaschachar/ae0de5b36a7f46211cfcc13636df468a to your computer and use it in GitHub Desktop.
func handleRequest(c *gin.Context) {
userObj := map[string]string{"userId": "user123"}
jsonString, _ := json.Marshal(userObj)
req, _ := http.NewRequest("POST", "http://localhost:8080/v1/activate", bytes.NewBuffer(jsonString))
q := req.URL.Query()
q.Add("featureKey", "hello_world")
req.URL.RawQuery = q.Encode()
req.Header.Add("X-Optimizely-SDK-Key", "DHbTLoxuXmGPHCTGbrSGKP")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var results []map[string]interface{}
json.NewDecoder(resp.Body).Decode(&results)
var enabled bool
enabled = results[0]["enabled"].(bool)
var message string
if enabled {
message = "Feature is ON!"
} else {
message = "Feature is off :("
}
c.JSON(200, gin.H{
"Go Service": message,
})
}
def hello_world():
sdk_key = 'DHbTLoxuXmGPHCTGbrSGKP'
s = requests.Session()
s.headers.update({'X-Optimizely-SDK-Key': sdk_key})
payload = {
"userId": "user123",
}
params = {
"featureKey": "hello_world"
}
resp = s.post(url = 'http://localhost:8080/v1/activate', params=params, json=payload)
feature_result = resp.json()[0]
print(json.dumps(feature_result, indent=2))
feature_text = "Feature is ON!" if feature_result['enabled'] else "Feature is off :("
return 'Python Service: ' + feature_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment