rollout

package module
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: MIT Imports: 7 Imported by: 0

README

gorollout

Fast and concurrent-safe feature flags for golang based on Redis. Inspired by the ruby rollout gem.

Build Status Code Coverage Go Report Card

Installation

go get github.com/salesloft/gorollout

Usage

package main

import (
    "github.com/go-redis/redis/v7"
    rollout "github.com/salesloft/gorollout"
)

var (
    apples = rollout.NewFeature("apples")
    bananas = rollout.NewFeature("bananas")
)

func main() {
    // instantiate a feature manager with a redis client and namespace prefix
    manager := rollout.NewManager(redis.NewClient(&redis.Options{}), "rollout")

    // activate a feature
    manager.Activate(apples)

    // deactivate a feature
    manager.Deactivate(apples)

    // rollout a feature to 25% of teams
    manager.ActivatePercentage(apples, 25)

    // explicitly activate a feature for team with id 99
    manager.ActivateTeam(99, apples)

    // check if a feature is active, globally
    manager.IsActive(apples)

    // check if a feature is active for a specific team
    manager.IsTeamActive(99, apples)

    // check multiple feature flags at once
    manager.IsActiveMulti(apples, bananas)
}

Command Line Interface (CLI)

gorollout also includes a command line interface for viewing and managing feature flags.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Feature represents a development feature toggle for rollout

func NewFeature

func NewFeature(name string) *Feature

NewFeature constructs a new Feature with the given name

func (*Feature) DecodeMsgpack

func (f *Feature) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack implements msgpack.CustomDecoder

func (*Feature) EncodeMsgpack

func (f *Feature) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack implements msgpack.CustomEncoder

func (*Feature) Name

func (f *Feature) Name() string

Name returns the name of the feature

type Manager

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

Manager persists and fetches feature toggles to/from redis

func NewManager

func NewManager(client redis.Cmdable, keyPrefix string) *Manager

NewManager constructs a new Manager instance

func (*Manager) Activate

func (m *Manager) Activate(feature *Feature) error

Activate globally activates the feature

func (*Manager) ActivatePercentage

func (m *Manager) ActivatePercentage(feature *Feature, percentage uint8) error

ActivatePercentage activates the feature for a percentage of teams

func (*Manager) ActivateTeam

func (m *Manager) ActivateTeam(teamID int64, feature *Feature) error

ActivateTeam activates the feature for specific team

func (*Manager) Deactivate

func (m *Manager) Deactivate(feature *Feature) error

Deactivate globally deactivates the feature

func (*Manager) DeactivateTeam

func (m *Manager) DeactivateTeam(teamID int64, feature *Feature) error

DeactivateTeam deactivates the feature for specific team

func (*Manager) IsActive

func (m *Manager) IsActive(feature *Feature) (bool, error)

IsActive returns whether the given feature is globally active

func (*Manager) IsActiveMulti

func (m *Manager) IsActiveMulti(features ...*Feature) ([]bool, error)

IsActiveMulti returns whether the given features are globally active

func (*Manager) IsTeamActive

func (m *Manager) IsTeamActive(teamID int64, feature *Feature) (bool, error)

IsTeamActive returns whether the given feature is active for a team

func (*Manager) IsTeamActiveMulti

func (m *Manager) IsTeamActiveMulti(teamID int64, features ...*Feature) ([]bool, error)

IsTeamActiveMulti returns whether the given features are globally active

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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