Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.cover
coverage.html
208 changes: 33 additions & 175 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,15 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/optimizely/go-sdk)](https://goreportcard.com/report/github.com/optimizely/go-sdk)
[![Coverage Status](https://coveralls.io/repos/github/optimizely/go-sdk/badge.svg?branch=master)](https://coveralls.io/github/optimizely/go-sdk?branch=master)

## Usage

### Instantiation
To start using the SDK, create an instance using our factory method:

```
import "github.com/optimizely/go-sdk/pkg/client"

optimizelyFactory := &client.OptimizelyFactory{
SDKKey: "[SDK_KEY_HERE]",
}

client, err := optimizelyFactory.Client()

// You can also instantiate with a hard-coded datafile
optimizelyFactory := &client.OptimizelyFactory{
Datafile: []byte("datafile_string"),
}

client, err := optimizelyFactory.Client()

```

### Feature Rollouts
```
import (
"github.com/optimizely/go-sdk/pkg/client"
"github.com/optimizely/go-sdk/pkg/entities"
)

user := entities.UserContext{
ID: "optimizely end user",
Attributes: map[string]interface{}{
"state": "California",
"likes_donuts": true,
},
}

enabled, _ := client.IsFeatureEnabled("binary_feature", user)
```

## Command line interface
A CLI has been provided to illustrate the functionality of the SDK. Simply run `go-sdk` for help.
```$sh
go-sdk provides cli access to your Optimizely fullstack project

Usage:
go-sdk [command]

Available Commands:
help Help about any command
is_feature_enabled Is feature enabled?
get_enabled_features Get enabled features
track Track a conversion event
get_feature_variable_boolean Get feature variable boolean value
get_feature_variable_double Get feature variable double value
get_feature_variable_integer Get feature variable integer value
get_feature_variable_string Get feature variable string value

Flags:
-h, --help help for go-sdk
-s, --sdkKey string Optimizely project SDK key

Use "go-sdk [command] --help" for more information about a command.
```

Each supported SDK API method is it's own [cobra](https://github.com/spf13/cobra) command and requires the
input of an `--sdkKey`.
## Installation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be easier to review by looking at the full file


### Installation
Install the CLI from github:
### Install from github:

```$sh
go install github.com/optimizely/go-sdk
```

Install the CLI from source:
### Install from source:
```$sh
go get github.com/optimizely/go-sdk
cd $GOPATH/src/github.com/optimizely/go-sdk
Expand All @@ -89,20 +21,22 @@ go install
NOTE:
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:

### Install using go.mod:

```
module mymodule

go 1.12

require (
github.com/optimizely/go-sdk v1.0.0-beta2
github.com/optimizely/go-sdk v1.0.0-beta6
)
```

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

```
go mod edit -require github.com/optimizely/go-sdk@v1.0.0-beta2
go mod edit -require github.com/optimizely/go-sdk@v1.0.0-beta6
```

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

### Commands

#### is_feature_enabled
```
Determines if a feature is enabled

Usage:
go-sdk is_feature_enabled [flags]

Flags:
-f, --featureKey string feature key to enable
-h, --help help for is_feature_enabled
-u, --userId string user id

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```

#### get_enabled_features
```
Returns enabled features for userId

Usage:
go-sdk get_enabled_features [flags]

Flags:
-h, --help help for get_enabled_features
-u, --userId string user id
## Usage

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```
### Instantiation
To start using the SDK, create an instance using our factory method:

#### track
```
Tracks a conversion event

Usage:
go-sdk track [flags]

Flags:
-e, --eventKey string event key to track
-h, --help help for track
-u, --userId string user id

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```
import "github.com/optimizely/go-sdk/pkg/client"

#### get_feature_variable_boolean
```
Returns feature variable boolean value
optimizelyFactory := &client.OptimizelyFactory{
SDKKey: "[SDK_KEY_HERE]",
}

Usage:
go-sdk get_feature_variable_boolean [flags]
client, err := optimizelyFactory.Client()

Flags:
-f, --featureKey string feature key for feature
-v, --variableKey string variable key for feature variable
-h, --help help for get_feature_variable_boolean
-u, --userId string user id
// You can also instantiate with a hard-coded datafile
optimizelyFactory := &client.OptimizelyFactory{
Datafile: []byte("datafile_string"),
}

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```
client, err := optimizelyFactory.Client()

#### get_feature_variable_double
```
Returns feature variable double value

Usage:
go-sdk get_feature_variable_double [flags]

Flags:
-f, --featureKey string feature key for feature
-v, --variableKey string variable key for feature variable
-h, --help help for get_feature_variable_double
-u, --userId string user id

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```

#### get_feature_variable_integer
### Feature Rollouts
```
Returns feature variable integer value

Usage:
go-sdk get_feature_variable_integer [flags]

Flags:
-f, --featureKey string feature key for feature
-v, --variableKey string variable key for feature variable
-h, --help help for get_feature_variable_integer
-u, --userId string user id
import (
"github.com/optimizely/go-sdk/pkg/client"
"github.com/optimizely/go-sdk/pkg/entities"
)

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```
user := entities.UserContext{
ID: "optimizely end user",
Attributes: map[string]interface{}{
"state": "California",
"likes_donuts": true,
},
}

#### get_feature_variable_string
enabled, _ := client.IsFeatureEnabled("binary_feature", user)
```
Returns feature variable string value

Usage:
go-sdk get_feature_variable_string [flags]

Flags:
-f, --featureKey string feature key for feature
-v, --variableKey string variable key for feature variable
-h, --help help for get_feature_variable_string
-u, --userId string user id

Global Flags:
-s, --sdkKey string Optimizely project SDK key
```

## Credits

Expand Down
57 changes: 0 additions & 57 deletions cmd/get_enabled_features.go

This file was deleted.

65 changes: 0 additions & 65 deletions cmd/get_feature_variable_boolean.go

This file was deleted.

Loading