https://github.com/xchapter7x/toggle
golang feature toggle library - a library to help make golang feature toggling clean and easy
https://github.com/xchapter7x/toggle
Last synced: 4 months ago
JSON representation
golang feature toggle library - a library to help make golang feature toggling clean and easy
- Host: GitHub
- URL: https://github.com/xchapter7x/toggle
- Owner: xchapter7x
- Created: 2014-10-18T17:57:18.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-17T17:19:37.000Z (over 10 years ago)
- Last Synced: 2025-02-26T03:35:44.622Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 594 KB
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
toggle
======
[](https://app.wercker.com/project/bykey/9c11e691895a9782a234fcc9bb313819)
[](http://godoc.org/github.com/xchapter7x/toggle)
[](https://coveralls.io/github/xchapter7x/toggle?branch=HEAD)
## supports env_variable backed toggling.
## It can also be updated via a pubsub interface (tested w/ redis)
## 2 engines for toggle backing are included
- Local Engine (only env variable backed)
- Local Engine PubSub (env variable backed w/ updates via redis pubsub)
## can be extended to support any 3rd party backing engine
func **Flip**(flg string, defaultFeature, newFeature interface{}, iargs ...interface{}) (responseInterfaceArray []interface{}) {}
func **SetFeatureStatus**(featureSignature, featureStatus string) (err error) {}
func **IsActive**(featureSignature string) (active bool) {}
func **Close**() {}
func **Init**(ns string, engine storageinterface.StorageEngine) {}
func **ShowFeatures**() map[string]*Feature {}
func **RegisterFeature**(featureSignature string) (err error) {}
func **GetFullFeatureSignature**(partialSignature string) (fullSignature string) {}
func **RegisterFeatureWithStatus**(featureSignature, statusValue string) (err error) {}
type Feature struct {
name string
Status string
filter func(...interface{}) bool
settings map[string]interface{}
}
func (s \*Feature) **UpdateStatus**(newStatus string) {}
type **DefaultEngine** struct
func (s \*DefaultEngine) **GetFeatureStatusValue**(featureSignature string) (status string, err error)
Sample usage:
(./sample/main.go)
```
package main
import (
"fmt"
"github.com/xchapter7x/goutil/unpack"
"github.com/xchapter7x/toggle"
)
func TestA(s string) (r string) {
r = fmt.Sprintln("testa", s)
fmt.Println(r)
return
}
func TestB(s string) (r string) {
r = fmt.Sprintln("testb", s)
fmt.Println(r)
return
}
func main() {
toggle.Init("MAINTEST", nil)
toggle.RegisterFeature("test")
output := ""
_, err := tgl.Flag("test").
On(testB).
Off(testA).
Args("argstring").
Returns(&output).
Run()
fmt.Println(output)
}
// or
func mainAlt() {
toggle.Init("MAINTEST", nil)
toggle.RegisterFeature("test")
f := toggle.Flip("test", TestA, TestB, "argstring")
var output string
unpack.Unpack(f, &output)
fmt.Println(output)
}
```
```
$ test=true go run sample/main.go
testb argstring
testb argstring
$ go run sample/main.go
testa argstring
testa argstring
```