optimizely

package module
v1.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 2 Imported by: 5

README

Optimizely Go SDK

Go Report Card Coverage Status

This repository houses the Go SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).

Optimizely Feature Experimentation is an A/B testing and feature management tool for product development teams that enables you to experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at Optimizely.com, or see the developer documentation.

Optimizely Rollouts is free feature flags for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.

Get Started

Refer to the Go SDK's developer documentation for detailed instructions on getting started with using the SDK.

Requirements

Requires Golang version 1.13 or higher.

Install the SDK
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/go-sdk@v1.0.0-rc1

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.

Use the Go SDK

See the example file in examples/main.go.

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

// Simple one-line initialization with the SDK key    
optlyClient, 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"),   
}    
optlyClient, err = optimizelyFactory.Client()
Make Decisions
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 
attributes := map[string]interface{}{ 
  "state": "California", 
  "likes_donuts": true, 
} 

user := client.CreateUserContext("optimizely end user", attributes) 
options := []decide.OptimizelyDecideOptions{decide.IncludeReasons} 

decision := user.Decide("my_flag", options) 
var variationKey string 
if variationKey = decision.VariationKey; variationKey == "" { 
  fmt.Printf("[decide] error: %v", decision.Reasons) 
  return 
} 

if variationKey == "control" { 
	// Execute code for control variation 
} else if variationKey == "treatment" { 
	// Execute code for treatment variation 
}

SDK Development

Unit Tests

Run

make test 
Contributing

Please see CONTRIBUTING.

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

Other Optimizely SDKs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(sdkKey string, options ...client.OptionFunc) (*client.OptimizelyClient, error)

Client returns an OptimizelyClient instantiated with the given key and options

func UserContext

func UserContext(userID string, attributes map[string]interface{}) entities.UserContext

UserContext is a helper method for creating a user context

Types

This section is empty.

Directories

Path Synopsis
pkg
client
Package client has client definitions
Package client has client definitions
config
Package config //
Package config //
config/datafileprojectconfig
Package datafileprojectconfig //
Package datafileprojectconfig //
config/datafileprojectconfig/entities
Package entities has entity definitions
Package entities has entity definitions
Package mappers ...
decide
Package decide has error definitions for decide api
Package decide has error definitions for decide api
decision
Package decision //
Package decision //
decision/bucketer
Package bucketer //
Package bucketer //
decision/evaluator
Package evaluator //
Package evaluator //
decision/evaluator/matchers
Package matchers //
Package matchers //
Package utils //
decision/reasons
Package reasons //
Package reasons //
entities
Package entities //
Package entities //
event
Package event //
Package event //
logging
Package logging //
Package logging //
metrics
Package metrics //
Package metrics //
notification
Package notification //
Package notification //
odp/utils
Package utils //
Package utils //
optimizelyjson
Package optimizelyjson //
Package optimizelyjson //
registry
Package registry is the global access point for retrieving instances of services by SDK Key //
Package registry is the global access point for retrieving instances of services by SDK Key //
utils
Package utils //
Package utils //

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL