Skip to content

Commit ab7cfc3

Browse files
author
Michael Ng
authored
feat(api): Add top-level wrapper for more convenient usage. (#191)
1 parent 619b3aa commit ab7cfc3

15 files changed

+67
-677
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.idea
12
.cover
23
coverage.html

README.md

Lines changed: 33 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,15 @@
33
[![Go Report Card](https://goreportcard.com/badge/github.com/optimizely/go-sdk)](https://goreportcard.com/report/github.com/optimizely/go-sdk)
44
[![Coverage Status](https://coveralls.io/repos/github/optimizely/go-sdk/badge.svg?branch=master)](https://coveralls.io/github/optimizely/go-sdk?branch=master)
55

6-
## Usage
7-
8-
### Instantiation
9-
To start using the SDK, create an instance using our factory method:
10-
11-
```
12-
import "github.com/optimizely/go-sdk/pkg/client"
13-
14-
optimizelyFactory := &client.OptimizelyFactory{
15-
SDKKey: "[SDK_KEY_HERE]",
16-
}
17-
18-
client, err := optimizelyFactory.Client()
19-
20-
// You can also instantiate with a hard-coded datafile
21-
optimizelyFactory := &client.OptimizelyFactory{
22-
Datafile: []byte("datafile_string"),
23-
}
24-
25-
client, err := optimizelyFactory.Client()
26-
27-
```
28-
29-
### Feature Rollouts
30-
```
31-
import (
32-
"github.com/optimizely/go-sdk/pkg/client"
33-
"github.com/optimizely/go-sdk/pkg/entities"
34-
)
35-
36-
user := entities.UserContext{
37-
ID: "optimizely end user",
38-
Attributes: map[string]interface{}{
39-
"state": "California",
40-
"likes_donuts": true,
41-
},
42-
}
43-
44-
enabled, _ := client.IsFeatureEnabled("binary_feature", user)
45-
```
46-
47-
## Command line interface
48-
A CLI has been provided to illustrate the functionality of the SDK. Simply run `go-sdk` for help.
49-
```$sh
50-
go-sdk provides cli access to your Optimizely fullstack project
51-
52-
Usage:
53-
go-sdk [command]
54-
55-
Available Commands:
56-
help Help about any command
57-
is_feature_enabled Is feature enabled?
58-
get_enabled_features Get enabled features
59-
track Track a conversion event
60-
get_feature_variable_boolean Get feature variable boolean value
61-
get_feature_variable_double Get feature variable double value
62-
get_feature_variable_integer Get feature variable integer value
63-
get_feature_variable_string Get feature variable string value
64-
65-
Flags:
66-
-h, --help help for go-sdk
67-
-s, --sdkKey string Optimizely project SDK key
68-
69-
Use "go-sdk [command] --help" for more information about a command.
70-
```
71-
72-
Each supported SDK API method is it's own [cobra](https://github.com/spf13/cobra) command and requires the
73-
input of an `--sdkKey`.
6+
## Installation
747

75-
### Installation
76-
Install the CLI from github:
8+
### Install from github:
779

7810
```$sh
7911
go install github.com/optimizely/go-sdk
8012
```
8113

82-
Install the CLI from source:
14+
### Install from source:
8315
```$sh
8416
go get github.com/optimizely/go-sdk
8517
cd $GOPATH/src/github.com/optimizely/go-sdk
@@ -89,20 +21,22 @@ go install
8921
NOTE:
9022
We practice trunk-based development, and as such our default branch, `master` might not always be the most stable. We do tag releases on Github and you can pin your installation to those particular release versions. One way to do this is to use [*Go Modules*](https://blog.golang.org/using-go-modules) for managing external dependencies:
9123

24+
### Install using go.mod:
25+
9226
```
9327
module mymodule
9428
9529
go 1.12
9630
9731
require (
98-
github.com/optimizely/go-sdk v1.0.0-beta2
32+
github.com/optimizely/go-sdk v1.0.0-beta6
9933
)
10034
```
10135

10236
If you are already using `go.mod` in your application you can run the following:
10337

10438
```
105-
go mod edit -require github.com/optimizely/[email protected]beta2
39+
go mod edit -require github.com/optimizely/[email protected]beta6
10640
```
10741

10842
NOTE:
@@ -115,122 +49,46 @@ go get github.com/optimizely/go-sdk/pkg
11549
```
11650
will install it as a package to pkg directory, rather than src directory. It could be useful for future development and vendoring.
11751

118-
### Commands
119-
120-
#### is_feature_enabled
121-
```
122-
Determines if a feature is enabled
123-
124-
Usage:
125-
go-sdk is_feature_enabled [flags]
126-
127-
Flags:
128-
-f, --featureKey string feature key to enable
129-
-h, --help help for is_feature_enabled
130-
-u, --userId string user id
131-
132-
Global Flags:
133-
-s, --sdkKey string Optimizely project SDK key
134-
```
135-
136-
#### get_enabled_features
137-
```
138-
Returns enabled features for userId
139-
140-
Usage:
141-
go-sdk get_enabled_features [flags]
142-
143-
Flags:
144-
-h, --help help for get_enabled_features
145-
-u, --userId string user id
52+
## Usage
14653

147-
Global Flags:
148-
-s, --sdkKey string Optimizely project SDK key
149-
```
54+
### Instantiation
55+
To start using the SDK, create an instance using our factory method:
15056

151-
#### track
15257
```
153-
Tracks a conversion event
154-
155-
Usage:
156-
go-sdk track [flags]
157-
158-
Flags:
159-
-e, --eventKey string event key to track
160-
-h, --help help for track
161-
-u, --userId string user id
162-
163-
Global Flags:
164-
-s, --sdkKey string Optimizely project SDK key
165-
```
58+
import "github.com/optimizely/go-sdk/pkg/client"
16659
167-
#### get_feature_variable_boolean
168-
```
169-
Returns feature variable boolean value
60+
optimizelyFactory := &client.OptimizelyFactory{
61+
SDKKey: "[SDK_KEY_HERE]",
62+
}
17063
171-
Usage:
172-
go-sdk get_feature_variable_boolean [flags]
64+
client, err := optimizelyFactory.Client()
17365
174-
Flags:
175-
-f, --featureKey string feature key for feature
176-
-v, --variableKey string variable key for feature variable
177-
-h, --help help for get_feature_variable_boolean
178-
-u, --userId string user id
66+
// You can also instantiate with a hard-coded datafile
67+
optimizelyFactory := &client.OptimizelyFactory{
68+
Datafile: []byte("datafile_string"),
69+
}
17970
180-
Global Flags:
181-
-s, --sdkKey string Optimizely project SDK key
182-
```
71+
client, err := optimizelyFactory.Client()
18372
184-
#### get_feature_variable_double
18573
```
186-
Returns feature variable double value
187-
188-
Usage:
189-
go-sdk get_feature_variable_double [flags]
190-
191-
Flags:
192-
-f, --featureKey string feature key for feature
193-
-v, --variableKey string variable key for feature variable
194-
-h, --help help for get_feature_variable_double
195-
-u, --userId string user id
196-
197-
Global Flags:
198-
-s, --sdkKey string Optimizely project SDK key
199-
```
20074

201-
#### get_feature_variable_integer
75+
### Feature Rollouts
20276
```
203-
Returns feature variable integer value
204-
205-
Usage:
206-
go-sdk get_feature_variable_integer [flags]
207-
208-
Flags:
209-
-f, --featureKey string feature key for feature
210-
-v, --variableKey string variable key for feature variable
211-
-h, --help help for get_feature_variable_integer
212-
-u, --userId string user id
77+
import (
78+
"github.com/optimizely/go-sdk/pkg/client"
79+
"github.com/optimizely/go-sdk/pkg/entities"
80+
)
21381
214-
Global Flags:
215-
-s, --sdkKey string Optimizely project SDK key
216-
```
82+
user := entities.UserContext{
83+
ID: "optimizely end user",
84+
Attributes: map[string]interface{}{
85+
"state": "California",
86+
"likes_donuts": true,
87+
},
88+
}
21789
218-
#### get_feature_variable_string
90+
enabled, _ := client.IsFeatureEnabled("binary_feature", user)
21991
```
220-
Returns feature variable string value
221-
222-
Usage:
223-
go-sdk get_feature_variable_string [flags]
224-
225-
Flags:
226-
-f, --featureKey string feature key for feature
227-
-v, --variableKey string variable key for feature variable
228-
-h, --help help for get_feature_variable_string
229-
-u, --userId string user id
230-
231-
Global Flags:
232-
-s, --sdkKey string Optimizely project SDK key
233-
```
23492

23593
## Credits
23694

cmd/get_enabled_features.go

Lines changed: 0 additions & 57 deletions
This file was deleted.

cmd/get_feature_variable_boolean.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)