Giter Site home page Giter Site logo

unleash-client-go's Introduction

Build Status GoDoc Go Report Card Coverage Status

unleash-client-go

Unleash Client for Go. Read more about the Unleash project

Version 3.x of the client requires unleash-server v3.x or higher.

Go Version

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.

Getting started

1. Install unleash-client-go

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

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/v3"
)

func init() {
	unleash.Initialize(
		unleash.WithListener(&unleash.DebugListener{}),
		unleash.WithAppName("my-application"),
		unleash.WithUrl("http://unleash.herokuapp.com/api/"),
		unleash.WithCustomHeaders(http.Header{"Authorization": {"<API token>"}}),
	)
}

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
  • FlexibleRolloutStrategy
  • 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

Adding client specifications

In order to make sure the unleash clients uphold their contract, we have defined a set of client specifications that define this contract. These are used to make sure that each unleash client at any time adhere to the contract, and define a set of functionality that is core to unleash. You can view the client specifications here.

In order to make the tests run please do the following steps.

// in repository root
// testdata is gitignored
mkdir testdata
cd testdata
git clone https://github.com/Unleash/client-specification.git

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

unleash-client-go's People

Contributors

chriswk avatar clairelee22 avatar fredrikoseberg avatar frekui avatar habibridho avatar itairegev avatar ivarconr avatar jallen-asapp avatar jrbarron avatar nilsmagnus avatar pschmidt88 avatar tormoder avatar wesleimp avatar

Watchers

 avatar

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.