https://github.com/optimizely/go-sdk-c-wrapper
A C wrapper for the Go SDK enabling Full Stack and Rollouts in C.
https://github.com/optimizely/go-sdk-c-wrapper
Last synced: 10 months ago
JSON representation
A C wrapper for the Go SDK enabling Full Stack and Rollouts in C.
- Host: GitHub
- URL: https://github.com/optimizely/go-sdk-c-wrapper
- Owner: optimizely
- License: apache-2.0
- Created: 2020-02-26T23:42:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-01T15:48:28.000Z (over 5 years ago)
- Last Synced: 2023-08-02T05:42:05.357Z (over 2 years ago)
- Language: Go
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 61
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Optimizely Go SDK C Wrapper
This repository contains a Go SDK C wrapper that enables the Go SDK to be used in C, C++ and other languages compiled to native code. This SDK is currently in Alpha.
## Installation
Download then build the SDK as shown below.
### Install from source:
```makefile
make
```
## Usage
### Instantiation
Include the headerfile and initialize the SDK with an SDK Key. The returned handle should be used in subsequent calls.
```c
#include
...
int handle = optimizely_sdk_client("");
```
See API for more details.
### Example: Feature Rollouts
To see if a feature has been enabled initialize the SDK then call `is_feature_enabled` function.
```c
...
int handle = optimizely_sdk_client(sdkkey);
if (handle == -1) {
fprintf(stderr, "failed to initialize Optimizely SDK\n");
return 1;
}
char *err = NULL;
int enabled = optimizely_sdk_is_feature_enabled(handle, feature_name, &attrib, &err);
...
```
For a full example see [examples/is-feature-enabled.c](https://github.com/optimizely/c-sdk/blob/master/examples/is-feature-enabled.c).
## API
**Important:** All strings and string arrays returned by the API must be free'd by the caller.
```c
typedef struct optimizely_user_attribute {
char *name;
int var_type; // 1 = string, 2 = bool, 3 = float, 4 = int
void *data;
} optimzely_user_attribute;
typedef struct optimizely_user_attributes {
char *id;
int num_attributes;
struct optimizely_user_attribute *user_attribute_list;
} optimizely_user_attributes;
// reintializes the SDK and creates a new handle table
int optimizely_sdk_init();
// creates a new optimizely SDK and returns a handle or returns -1 if the sdk could not be initialized
int optimizely_sdk_client(char* sdkkey);
// removes the passed in client handle
void optimizely_sdk_delete_client(int handle);
// checks to see if feature_name is enabled, non zero return means the feature is enabled
int optimizely_sdk_is_feature_enabled(int handle, char* feature_name,
optimizely_user_attributes* attributes, char** error);
// returns the string feature variable value
char* optimizely_sdk_get_feature_variable_string(int handle, char* feature_name, char* variable_key,
optimizely_user_attributes* attributes, char** error);
// returns the boolean feature variable value
int optimizely_sdk_get_feature_variable_boolean(int handle, char* feature_name, char* variable_key,
optimizely_user_attributes* attributes, char** error);
// returns the double feature variable value
double optimizely_sdk_get_feature_variable_double(int handle, char* feature_name, char* variable_key,
optimizely_user_attributes* attributes,
char** error);
// returns the integer feature variable value
int optimizely_sdk_get_feature_variable_integer(int handle, char* feature_name, char* variable_key,
optimizely_user_attributes* attributes, char** error);
// returns the variation for the specified experiment key and user attributes
char* optimizely_sdk_get_variation(int handle, char* experiment_key,
optimizely_user_attributes* attributes, char** error);
// returns the feature variable for the specified feature_name and variable_key
// the variable_type receives a string specifying the variable type
char* optimizely_sdk_get_feature_variable(int handle, char* feature_name, char* variable_key,
optimizely_user_attributes* attributes,
char** variable_type, char** error);
// activates the specified experiment_key
char* optimizely_sdk_activate(int handle, char* experiment_key,
optimizely_user_attributes* attributes, char** error);
// returns a list of the enabled features, the count receives the number of features returned
char** optimizely_sdk_get_enabled_features(int handle, optimizely_user_attributes* attributes,
int* count, char** error);
// returns a list of the enabled feature variables, count contains the feature variable count
// to get the value of a feature variable call optimizely_sdk_get_feature_variable_()
char** optimizely_sdk_get_all_feature_variables(int handle, char* feature_key,
optimizely_user_attributes* attributes,
int* enabled, int* count, char** error);
// tracks the specified event_key
char* optimizely_sdk_track(int handle, char* event_key, optimizely_user_attributes* attributes,
float* value, char** error);
```
## Credits
This software is built with the following software.
* Golang (c) 2009 The Go Authors License, [BSD 3-Clause](https://golang.org/LICENSE)