https://github.com/piszmog/gotoggle
Feature Toggles for Go
https://github.com/piszmog/gotoggle
Last synced: about 2 months ago
JSON representation
Feature Toggles for Go
- Host: GitHub
- URL: https://github.com/piszmog/gotoggle
- Owner: Piszmog
- License: mit
- Created: 2019-04-07T15:35:19.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2019-10-18T20:47:45.000Z (over 5 years ago)
- Last Synced: 2025-03-22T07:59:24.662Z (2 months ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Go Feature Toggle
[](https://travis-ci.org/Piszmog/gotoggle)
[](https://coveralls.io/github/Piszmog/gotoggle?branch=develop)
[](https://goreportcard.com/report/github.com/Piszmog/gotoggle)
[](https://github.com/Piszmog/gotoggle/releases/latest)
[](https://opensource.org/licenses/MIT)This is a simple package for using feature toggles in Go.
To use, simply initialize the features with a configuration or use `gotoggle.AddFeatures(..)` / `gotoggle.AddFeature(..)`
to setup the features. Then use `gotoggle.IsEnabled(..)` to determine if a feature is enabled.Determining if a feature is enabled is case insensitive. There is no different between "myFeature" and "myfeature".
## Example
```go
package mainimport (
"encoding/json"
"github.com/Piszmog/gotoggle"
)func main() {
configJSON := `{"features":{"feature1":true,"feature2":false}}`
var config gotoggle.Configuration
err := json.Unmarshal([]byte(configJSON), &config)
if err != nil {
// do something
}
gotoggle.InitializeFeatures(config)
// ...
if gotoggle.IsEnabled("myFeature") {
// do something
}
}
```### Usage
Initializing or adding features should be done once. Under the hood, the feature map is not safe to update in many
different goroutines. You can access the features from different goroutines.