Documentation ΒΆ
Overview ΒΆ
Package ffclient aids adding instrumentation to have feature flags in your app without any backend server.
Summary ΒΆ
This package and its subpackages contain bits of code to have an easy feature flag solution with no complex installation to do on your infrastructure and without using 3rd party vendor for this.
The ffclient package provides the entry point - initialization and the basic method to get your flags value.
Before using the module you need to initialized it this way:
func main() { err := ffclient.Init(ffclient.Config{ PollInterval: 3, HTTPRetriever: &ffClient.HTTPRetriever{ URL: "http://example.com/test.yaml", }, }) defer ffclient.Close() ...
This example will load a file from an HTTP endpoint and will refresh the flags every 3 seconds.
Now you can evalute your flags anywhere in your code.
func main() { ... user := ffuser.NewUser("user-unique-key") hasFlag, _ := ffclient.BoolVariation("test-flag", user, false) if hasFlag { //flag "test-flag" is true for the user } else { // flag "test-flag" is false for the user } ...
Index ΒΆ
- func BoolVariation(flagKey string, user ffuser.User, defaultValue bool) (bool, error)
- func Close()
- func Float64Variation(flagKey string, user ffuser.User, defaultValue float64) (float64, error)
- func Init(config Config) error
- func IntVariation(flagKey string, user ffuser.User, defaultValue int) (int, error)
- func JSONArrayVariation(flagKey string, user ffuser.User, defaultValue []interface{}) ([]interface{}, error)
- func JSONVariation(flagKey string, user ffuser.User, defaultValue map[string]interface{}) (map[string]interface{}, error)
- func StringVariation(flagKey string, user ffuser.User, defaultValue string) (string, error)
- type Config
- type HTTPRetriever
- type S3Retriever
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func BoolVariation ΒΆ
BoolVariation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
func Close ΒΆ
func Close()
Close the component by stopping the background refresh and clean the cache.
func Float64Variation ΒΆ
Float64Variation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
func Init ΒΆ
Init the feature flag component with the configuration of ffclient.Config
func main() { err := ffclient.Init(ffclient.Config{ PollInterval: 3, HTTPRetriever: &ffClient.HTTPRetriever{ URL: "http://example.com/test.yaml", }, }) defer ffclient.Close()
func IntVariation ΒΆ
IntVariation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
func JSONArrayVariation ΒΆ
func JSONArrayVariation(flagKey string, user ffuser.User, defaultValue []interface{}) ([]interface{}, error)
JSONArrayVariation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
func JSONVariation ΒΆ
func JSONVariation( flagKey string, user ffuser.User, defaultValue map[string]interface{}) (map[string]interface{}, error)
JSONVariation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
func StringVariation ΒΆ
StringVariation return the value of the flag in boolean. An error is return if you don't have init the library before calling the function. If the key does not exist we return the default value.
Types ΒΆ
type Config ΒΆ
type Config struct { PollInterval int // Poll every X seconds LocalFile string HTTPRetriever *HTTPRetriever S3Retriever *S3Retriever }
Config is the configuration of go-feature-flag. PollInterval is the interval in seconds where we gonna read the file to update the cache. You should also have a retriever to specify where to read the flags file.
func (*Config) GetRetriever ΒΆ
func (c *Config) GetRetriever() (retriever.FlagRetriever, error)
GetRetriever is used to get the retriever we will use to load the flags file.
type HTTPRetriever ΒΆ
HTTPRetriever is a configuration struct for an HTTP endpoint retriever.