rollout

package module
v0.0.0-...-6a01ba9 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: MIT Imports: 3 Imported by: 0

README

rollout Build Status Code Coverage

Feature based rollout for Golang.

Installation

go get github.com/fbeline/rollout

Introduction

rollout is a library used to create feature rollouts based on percentage.

usage examples:

  • You have a new feature and you want to expose that only for 5% of your userbase.

  • A/B tests.

The library is free of any persistence system, but I strongly recommend to you to persist the rollout state at disk instead make it hardcoded. In that way, you will be able to fast manipulate the rollout percentages and status.

How to use

import the rollout package

import "github.com/fbeline/rollout"
Creating a rollout
var foo = rollout.Feature{Name: "foo", Percentage: 0.5, Active: true, Whitelist: []string{}}
var bar = rollout.Feature{Name: "bar", Percentage: 0.7, Active: true, Whitelist: []string{}}
var features = []rollout.Feature{foo, bar}
var r = rollout.Create(features)
Check if a feature is active for a given user
<rollout instance>.IsActive("featureName", "UserId")
Upsert a feature

The feature name is used as a unique key. If the feature exists it will be updated otherwise created.

var newFoo = rollout.Feature{Name: "foo", Percentage: 0.8, Active: true}
<rollout instance>.Set(newFoo)
Checking if a feature is active
<rollout instance>.IsFeatureActive("featureName")
Activate a feature
<rollout instance>.Activate("featureName")
Deactivate a feature
<rollout instance>.Deactivate("featureName")
Get a feature

The first value (f) is assigned the value stored under the feature name.The second value (ok) is a bool that is true if the feature exists, and false if not.

f, ok := <rollout instance>.Get("featureName")
Get all features
<rollout instance>.GetAll()

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature struct {
	Name       string
	Percentage float64
	Active     bool
	Whitelist  []string
}

Feature struct keeps the main information of a feature as: identification, the percentage of users that will be affected and status

type Rollout

type Rollout struct {
	// contains filtered or unexported fields
}

Rollout component struct

func Create

func Create(features []Feature) *Rollout

Create is function used to create a new Rollout

func (*Rollout) Activate

func (r *Rollout) Activate(feature string)

Activate active a feature if the feature does not exists the action is ignored

func (*Rollout) Deactivate

func (r *Rollout) Deactivate(feature string)

Deactivate deactivate a feature if the feature does not exists the action is ignored

func (Rollout) Get

func (r Rollout) Get(feature string) (Feature, bool)

Get a feature by name

func (Rollout) GetAll

func (r Rollout) GetAll() []Feature

GetAll get all features

func (Rollout) IsActive

func (r Rollout) IsActive(feature string, id string) bool

IsActive will check if a given user is active for a feature

func (Rollout) IsFeatureActive

func (r Rollout) IsFeatureActive(feature string) bool

IsFeatureActive checks if a feature is active

func (*Rollout) Set

func (r *Rollout) Set(feature Feature)

Set upsert a feature inside rollout component

Jump to

Keyboard shortcuts

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