Documentation ¶
Overview ¶
Package toggles defines a standard way to define, list, and use feature toggles in the service broker.
It mimics Go's `flags` package, but uses Viper as a backing store to abstract out how a particular flag is set.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Compatibility = NewToggleSet("compatibility.")
Compatibility is the default set of flags for enabling compatibility modes.
var Feature = NewToggleSet("feature.")
Feature is the default set of flags for enabling or disabling features.
Functions ¶
This section is empty.
Types ¶
type Toggle ¶
type Toggle struct { Name string Default bool Description string // contains filtered or unexported fields }
Toggle represents a single feature that the user can enable or disable.
func (Toggle) EnvironmentVariable ¶
EnvironmentVariable gets the environment variable used to control the toggle.
Example ¶
ts := NewToggleSet("foo.") toggle := ts.Toggle("bar", true, "bar gets a default of true") fmt.Println(toggle.EnvironmentVariable())
Output: GSB_FOO_BAR
func (Toggle) IsActive ¶
IsActive returns true if the toggle is enabled and false if it isn't.
Example ¶
ts := NewToggleSet("foo.") toggle := ts.Toggle("bar", true, "bar gets a default of true") fmt.Println(toggle.IsActive()) viper.Set("foo.bar", "false") fmt.Println(toggle.IsActive())
Output: true false
type ToggleSet ¶
type ToggleSet struct {
// contains filtered or unexported fields
}
A ToggleSet represents a set of defined toggles. The zero value of a ToggleSet has no property prefix.
func NewToggleSet ¶
NewFlagSet returns a new, empty toggle set with the specified property prefix. The property prefix will be prepended to any toggles exactly as-is. You MUST specify a trailing period if you want your properties to be namespaced.
func (*ToggleSet) Toggle ¶
Toggle creates a new toggle with the given name, default value, label and description. It also adds the toggle to an internal registry and initializes the default value in viper.
func (*ToggleSet) Toggles ¶
Toggles returns a list of all registered toggles sorted lexicographically by their property name.
Example ¶
ts := NewToggleSet("foo.") // add some toggles ts.Toggle("z", true, "a toggle") ts.Toggle("a", false, "another toggle") ts.Toggle("b", true, "a third toggle") for _, tgl := range ts.Toggles() { fmt.Printf("name: %s, var: %s, description: %q, default: %v\n", tgl.Name, tgl.EnvironmentVariable(), tgl.Description, tgl.Default) }
Output: name: a, var: GSB_FOO_A, description: "another toggle", default: false name: b, var: GSB_FOO_B, description: "a third toggle", default: true name: z, var: GSB_FOO_Z, description: "a toggle", default: true