Unleash Client for Go
Switch branches/tags
Clone or download
jrbarron Add a note about v3
For compatibility reasons, we cannot switch the master branch over to
using v3 so we need a notice pointing people to the right version.
1
Latest commit ae068e0 Nov 21, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
context Run go fmt to fix minor formatting issues. Mar 8, 2017
internal Fix gradualRolloutRandom when percentage is 0 Sep 14, 2018
strategy Fix the casing on the organization name unleash -> Unleash. Mar 8, 2017
.gitignore Add a .gitignore file. Mar 4, 2017
.travis.yml Add -v to the 'go test' call in .travis.yml Oct 24, 2018
LICENSE Initial commit Jan 2, 2017
Makefile Remove deletion of png files May 18, 2018
README.md Add a note about v3 Nov 21, 2018
client.go Go fmt Nov 16, 2017
config.go Go fmt Nov 16, 2017
debuglistener.go Add some documentation Mar 4, 2017
doc.go Fix the casing on the organization name unleash -> Unleash. Mar 8, 2017
example_custom_strategy_test.go Removing global unleash instances from unit tests Oct 24, 2018
example_simple_usage_test.go Removing global unleash instances from unit tests Oct 24, 2018
example_with_instance_test.go Fix the casing on the organization name unleash -> Unleash. Mar 8, 2017
go.mod Update go.mod file after running all the tests Oct 24, 2018
go.sum Update go.mod file after running all the tests Oct 24, 2018
metrics.go metrics: defer closing http response bodies Nov 21, 2018
metrics_test.go More work on tests. Oct 4, 2017
repository.go Add support for specifying custom headers Jun 26, 2017
storage.go Add some documentation Mar 4, 2017
unleash.go Add some documentation Mar 4, 2017
unleash_test.go Go fmt Nov 16, 2017
utils.go Rename package to "unleash". Mar 2, 2017

README.md

Build Status GoDoc Go Report Card

unleash-client-go

Unleash Client for Go. Read more about the Unleash project

NOTE The following instructions are for the v2 client which does not work with the latest version of the Unleash Server (v3) unless legacy routes are enabled. It is recommended that you use the v3 branch:

go get github.com/Unleash/unleash-client-go/v3
import (
	"github.com/Unleash/unleash-client-go/v3"
)

Getting started

1. Install unleash-client-go

go get github.com/Unleash/unleash-client-go

2. Initialize unleash

The easiest way to get started with Unleash is to initialize it early in your application code:

import (
	"github.com/Unleash/unleash-client-go"
)

func init() {
	unleash.Initialize(
		unleash.WithListener(&unleash.DebugListener{}),
		unleash.WithAppName("my-application"),
		unleash.WithUrl("http://unleash.herokuapp.com/api/"),
	)
}

3. Use unleash

After you have initialized the unleash-client you can easily check if a feature toggle is enabled or not.

unleash.IsEnabled("app.ToggleX")

4. Stop unleash

To shut down the client (turn off the polling) you can simply call the destroy-method. This is typically not required.

unleash.Close()

Built in activation strategies

The Go client comes with implementations for the built-in activation strategies provided by unleash.

  • DefaultStrategy
  • UserIdStrategy
  • GradualRolloutUserIdStrategy
  • GradualRolloutSessionIdStrategy
  • GradualRolloutRandomStrategy
  • RemoteAddressStrategy
  • ApplicationHostnameStrategy

Read more about the strategies in activation-strategy.md.

Unleash context

In order to use some of the common activation strategies you must provide a unleash-context. This client SDK allows you to send in the unleash context as part of the isEnabled call:

ctx := context.Context{
    UserId: "123",
    SessionId: "some-session-id",
    RemoteAddress: "127.0.0.1",
}

unleash.IsEnabled("someToggle", unleash.WithContext(ctx))

Caveat

This client uses go routines to report several events and doesn't drain the channel by default. So you need to either register a listener using WithListener or drain the channel "manually" (demonstrated in this example).

Development

Requirements:

  • make
  • golint (go get -u golang.org/x/lint/golint)

Run tests:

make 

Run lint check:

make lint

Run code-style checks:(currently failing)

make strict-check

Run race-tests(currently failing):

make test-all