Last active
June 8, 2020 22:49
-
-
Save asaschachar/ae0de5b36a7f46211cfcc13636df468a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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