Unleash Client for Go. Read more about the Unleash project
Version 3.x of the client requires unleash-server
v3.x or higher.
The client is currently tested against Go 1.10.x and 1.13.x. These versions will be updated as new versions of Go are released.
The client may work on older versions of Go as well, but are not actively tested.
To install the latest version of the client use:
go get github.com/Unleash/unleash-client-go/v3
If you are still using Unleash Server v2.x.x, then you should use:
go get github.com/Unleash/unleash-client-go
The easiest way to get started with Unleash is to initialize it early in your application code:
import (
"github.com/Unleash/unleash-client-go/v3"
)
func init() {
unleash.Initialize(
unleash.WithListener(&unleash.DebugListener{}),
unleash.WithAppName("my-application"),
unleash.WithUrl("http://unleash.herokuapp.com/api/"),
)
}
After you have initialized the unleash-client you can easily check if a feature toggle is enabled or not.
unleash.IsEnabled("app.ToggleX")
To shut down the client (turn off the polling) you can simply call the destroy-method. This is typically not required.
unleash.Close()
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.
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))
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).
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:
make test-all