• Stars
    star
    388
  • Rank 110,734 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Feature flags API written in Go

Travis CI Software License GoDoc Coverage Status

Feature flags API in Go

This package uses boltdb/bolt, a key-value store for storage. You do not need to connect another database! The HTTP routing is done by gorilla/mux.

What are feature flags?

Feature flags let you enable or disable some features of your application, for example when you're under unexpected traffic or when you want to let some users try a new feature you've been working on. They decouple feature release and code deployment, so that you can release features whenever you want, instead of whenever the code happens to ship.

With this package, you can enable the access of a feature for:

  • specific user IDs
  • specific groups
  • a percentage of your user base
  • everyone
  • no one

And you can combine things! You can give access to a feature for users in the group dev or admin and for users 1337 and 42 if you want to.

If you want to know everything about feature flags, check out this article.

Getting started

You can grab this package with the following command:

go get gopkg.in/antoineaugusti/feature-flags.v0

And then build it:

cd ${GOPATH%/}/src/github.com/antoineaugusti/feature-flags
go build

Usage

From the -h flag:

Usage of ./feature-flags:
  -a string
        address to listen (default ":8080")
  -d string
        location of the database file (default "bolt.db")

Authentication

This API does not ship with an authentication layer. You should not expose the API to the Internet. This API should be deployed behind a firewall, only your application servers should be allowed to send requests to the API.

API Endpoints

API Documentation

GET /features

Get a list of available feature flags.

  • Method: GET
  • Endpoint: /features
  • Responses:
    • 200 OK
    [
       {
          "key":"homepage_v2",
          "enabled":false,
          "users":[],
          "groups":[
             "dev",
             "admin"
          ],
          "percentage":0
       },
       {
          "key":"portfolio",
          "enabled":false,
          "users":[
             1337,
             42
          ],
          "groups":[
             "dev",
             "admin"
          ],
          "percentage":50
       }
    ]
    • key is the name of the feature flag
    • enabled: tell if the feature flag is enabled. If true, everybody has access to the feature flag. Otherwise, the access rule depends on the value of the other attributes.
    • users: an array of user IDs who can have access to the feature even if it's disabled.
    • groups: an array of group names which can have access to the feature even if it's disabled.
    • percentage: a number between 0 and 100. If the percentage is 50, 50% of the user base is going to have access to the feature.

POST /features

Create a new feature flag.

  • Method: POST

  • Endpoint: /features

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "key":"homepage_v2",
      "enabled":false,
      "users":[],
      "groups":[
         "dev",
         "admin"
      ],
      "percentage":0
    }
  • Responses:

    • 201 Created
    {
      "key":"homepage_v2",
      "enabled":false,
      "users":[],
      "groups":[
         "dev",
         "admin"
      ],
      "percentage":0
    }
    • 422 Unprocessable entity:
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }
    • 400 Bad Request
    {
      "status":"invalid_feature",
      "message":"<reason>"
    }

    Common reasons:

    • the feature key already exists. The message will be Feature already exists
    • the percentage must be between 0 and 100
    • the feature key must be between 3 and 50 characters
    • the feature key must only contain digits, lowercase letters and underscores

GET /features/:featureKey

Get a specific feature flag.

  • Method: GET
  • Endpoint: /features/:featureKey
  • Responses:
    • 200 OK
    {
      "key":"homepage_v2",
      "enabled":false,
      "users":[],
      "groups":[
         "dev",
         "admin"
      ],
      "percentage":0
    }
    • 404 Not Found
    {
      "status":"feature_not_found",
      "message":"The feature was not found"
    }

DELETE /features/:featureKey

Remove a feature flag.

  • Method: DELETE
  • Endpoint: /features/:featureKey
  • Responses:
    • 200 OK
    {
      "status":"feature_deleted",
      "message":"The feature was successfully deleted"
    }
    • 404 Not Found
    {
      "status":"feature_not_found",
      "message":"The feature was not found"
    }

PATCH /features/:featureKey

Update a feature flag.

  • Method: PATCH

  • Endpoint: /features/:featureKey

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "enabled":true,
      "users":[
        13,
        37
      ],
      "groups":[
         "dev"
      ],
      "percentage":42
    }
  • Responses:

    • 200 OK
    {
      "key":"homepage_v2",
      "users":[
        13,
        37
      ],
      "groups":[
         "dev"
      ],
      "percentage":42
    }
    • 404 Not Found
    {
      "status":"feature_not_found",
      "message":"The feature was not found"
    }
    • 422 Unprocessable entity:
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }
    • 400 Bad Request
    {
      "status":"invalid_feature",
      "message":"<reason>"
    }

    Common reason:

    • the percentage must be between 0 and 100

POST /features/access

Get a list of accessible features for a user or a list of groups.

  • Method: POST

  • Endpoint: /features/access

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "groups":[
         "dev",
         "test"
      ],
      "user":42
    }
  • Responses:

    • 200 OK

    Same as in POST /features. An empty array indicates that no known features are accessible for the given input.

    • 422 Unprocessable entity:
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }

POST /features/:featureKey/access

Check if a feature flag is enabled for a user or a list of groups.

  • Method: POST

  • Endpoint: /features/:featureKey/access

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "groups":[
         "dev",
         "test"
      ],
      "user":42
    }
  • Responses:

    • 200 OK
    {
      "status":"has_access",
      "message":"The user has access to the feature"
    }
    {
      "status":"not_access",
      "message":"The user does not have access to the feature"
    }
    • 404 Not Found
    {
      "status":"feature_not_found",
      "message":"The feature was not found"
    }
    • 422 Unprocessable entity:
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }

More Repositories

1

laravel-easyrec

Laravel wrapper for the recommendation system Easyrec
PHP
54
star
2

laravel-sentiment-analysis

A Laravel wrapper to perform sentiment analysis over an English sentence
Hack
43
star
3

vacances-scolaires-france

Connaître les dates des vacances scolaires en France
Python
31
star
4

go-exercices

Exercices from the Go tour
Go
29
star
5

moduluschecking

Check that a UK bank account number is valid using the VocaLink UK specification
Go
24
star
6

EasyPHPCharts

A simple PHP class for http://www.chartjs.org charts. Draw a beautiful chart with 5 lines of PHP!
PHP
24
star
7

bagging-boosting-random-forests

Bagging, boosting and random forests in Matlab
MATLAB
22
star
8

updown

Go client for the Updown API
Go
15
star
9

api-jours-feries-france

Une API REST pour les jours fériés en France
Python
15
star
10

radars-france

Radars automatiques en France
Python
14
star
11

wordsegmentation

Word segmentation problem in Golang
Go
14
star
12

vacances-scolaires

Vacances scolaires en France
Python
13
star
13

table-schema-to-markdown

Crée un fichier de documentation Markdown à partir d'un fichier Table Schema
Python
9
star
14

google-search-gdpr

Transform your Google Search GDPR export in CSV
Python
8
star
15

jours-feries-france-datagouv

Dumps CSV des jours féries en France
Python
6
star
16

gharchive-gouv-fr

Download GitHub push events done by .gouv.fr email addresses
Python
6
star
17

trainline-gdpr

Analyze your personal data coming from Trainline
Python
5
star
18

katas

Code katas
Python
5
star
19

google-books

PHP client for the Google Books API
PHP
5
star
20

citymapper-mobility-index

Data scrapped from Citymapper Mobility Index
Python
5
star
21

moduluschecking-api

API to validate UK bank account numbers, supporting authentication and rate limits
Go
4
star
22

avurnav-api

Exposes in-force navigational warnings for metropolitan France
Go
4
star
23

fake-google

Faking multiple distributed search services
Go
4
star
24

mestrainsdhier-sncf

Archives des données de régularité quotidiennes des TGV, TER, Transilien et Intercités
HTML
4
star
25

internet-facts

Quotes' website about fun facts
PHP
3
star
26

doctolib-vaccins

Savoir s'il y a des disponibilités pour une injection de 1ère dose dans certains centres en France
Python
3
star
27

crawler

Crawl, process and find children resources
Go
3
star
28

glyphosate

Statistiques sur les réductions de production ou la sortie du glyphosate par département
Python
3
star
29

avurnav

Get navigational warnings for metropolitan France
Go
2
star
30

schema-web

CSS
2
star
31

purchasing-power

Archive daily data about purchasing power parity: how much goods should cost in various countries
Python
2
star
32

antoine-augusti.fr

My personnal website
HTML
2
star
33

transitapp

Tracks when a new region is added to Transit
Python
1
star
34

colors

CSS color parser in Go
Go
1
star
35

wallpapers

1
star
36

diviavelodi-data

Historique des données de disponibilité de DiviaVélodi
Python
1
star
37

referendum-animaux

Python
1
star
38

reponses-cada

Taux de réponse à la Commission d'accès aux documents administrations
Python
1
star
39

prix-timbre-france

Prix du timbre pour envoyer une lettre de 20 grammes depuis 1983
1
star
40

webconf-rie-stats

Statistiques de l'usage de la webconférence de l'État français
Python
1
star
41

tangerine-rates

Twitter bot: post a tweet when Tangerine rates change
Python
1
star
42

NoSQL-etatart

État de l'art des bases de données NoSQL
TeX
1
star
43

solid-principles

Describe SOLID principles
1
star
44

loto

Règles du Loto en France du 6 octobre 2008 au 6 mars 2017
Python
1
star
45

tweets-rerb

Archivage des tweets du compte RER B
Python
1
star
46

technostress

PHP
1
star
47

diviapark-history

Python
1
star
48

correcteur-orthographique

Correcteur orthographique en C, multi-langages. Réalisé à l'INSA de Rouen par Antoine Augusti, Étienne Batise, Jean-Claude Bernard, Thibaud Dauce et Faustine Demiselle.
C
1
star
49

antennes-free

Historique des antennes relais Free Mobile en maintenance ou en panne
Shell
1
star