Git Product home page Git Product logo

go-sdk's Introduction

Optimizely Go SDK

Go Report Card Coverage Status

Installation

Install from github:

go get github.com/optimizely/go-sdk

Install from source:

go get github.com/optimizely/go-sdk
cd $GOPATH/src/github.com/optimizely/go-sdk
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 for managing external dependencies:

Install using go.mod:

module mymodule

go 1.12

require (
	github.com/optimizely/go-sdk v1.0.0-rc1
)

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

go mod edit -require github.com/optimizely/[email protected]

NOTE:

go get github.com/optimizely/go-sdk/...

or

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.

Usage

Instantiation

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

import optly "github.com/optimizely/go-sdk"
import "github.com/optimizely/go-sdk/client"

// Simple one-line initialization with the SDK key
client, err := optly.Client("SDK_KEY")

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

client, err = optimizelyFactory.Client()

Feature Rollouts

import (
  optly "github.com/optimizely/go-sdk"
)

// instantiate a client
client, err := optly.Client("SDK_KEY")

// User attributes are optional and used for targeting and results segmentation
atributes := map[string]interface{}{
     "state":      "California",
     "likes_donuts": true,
}, 
user := optly.UserContext("optimizely end user", attributes)
enabled, _ := client.IsFeatureEnabled("binary_feature", user)

Credits

This software is distributed with code from the following open source projects:

murmur3 Copyright 2013, Sébastien Paolacci. License (BSD-3 Clause): https://github.com/twmb/murmur3/blob/master/LICENSE

uuid Copyright (c) 2009, 2014 Google Inc. All rights reserved. License (BSD-3 Clause): https://github.com/google/uuid/blob/master/LICENSE

testify Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell. License (MIT): https://github.com/stretchr/testify/blob/master/LICENSE

json-iterator Copyright (c) 2016 json-iterator License (MIT): https://github.com/json-iterator/go/blob/master/LICENSE

subset Copyright (c) 2015, Facebook, Inc. All rights reserved. License (BSD): https://github.com/facebookarchive/subset/blob/master/license

profile Copyright (c) 2013 Dave Cheney. All rights reserved. License (BSD): https://github.com/pkg/profile/blob/master/LICENSE

sync Copyright (c) 2009 The Go Authors. All rights reserved. https://github.com/golang/sync/blob/master/LICENSE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.