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{ PollingInterval: 3 * time.Second, HTTPRetriever: &httpretriever.Retriever{ URL: "http://example.com/flag-config.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 evaluate your flags anywhere in your code.
func main() { ... user := ffcontext.NewEvaluationContext("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 AllFlagsState(ctx ffcontext.Context) flagstate.AllFlags
- func BoolVariation(flagKey string, ctx ffcontext.Context, defaultValue bool) (bool, error)
- func BoolVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue bool) (model.VariationResult[bool], error)
- func Close()
- func Float64Variation(flagKey string, ctx ffcontext.Context, defaultValue float64) (float64, error)
- func Float64VariationDetails(flagKey string, ctx ffcontext.Context, defaultValue float64) (model.VariationResult[float64], error)
- func GetCacheRefreshDate() time.Time
- func GetFlagsFromCache() (map[string]flag.Flag, error)
- func Init(config Config) error
- func IntVariation(flagKey string, ctx ffcontext.Context, defaultValue int) (int, error)
- func IntVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue int) (model.VariationResult[int], error)
- func JSONArrayVariation(flagKey string, ctx ffcontext.Context, defaultValue []interface{}) ([]interface{}, error)
- func JSONArrayVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue []interface{}) (model.VariationResult[[]interface{}], error)
- func JSONVariation(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}) (map[string]interface{}, error)
- func JSONVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}) (model.VariationResult[map[string]interface{}], error)
- func StringVariation(flagKey string, ctx ffcontext.Context, defaultValue string) (string, error)
- func StringVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue string) (model.VariationResult[string], error)
- type Config
- type DataExporter
- type GoFeatureFlag
- func (g *GoFeatureFlag) AllFlagsState(ctx ffcontext.Context) flagstate.AllFlags
- func (g *GoFeatureFlag) BoolVariation(flagKey string, ctx ffcontext.Context, defaultValue bool) (bool, error)
- func (g *GoFeatureFlag) BoolVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue bool) (model.VariationResult[bool], error)
- func (g *GoFeatureFlag) Close()
- func (g *GoFeatureFlag) CollectEventData(event exporter.FeatureEvent)
- func (g *GoFeatureFlag) Float64Variation(flagKey string, ctx ffcontext.Context, defaultValue float64) (float64, error)
- func (g *GoFeatureFlag) Float64VariationDetails(flagKey string, ctx ffcontext.Context, defaultValue float64) (model.VariationResult[float64], error)
- func (g *GoFeatureFlag) GetCacheRefreshDate() time.Time
- func (g *GoFeatureFlag) GetFlagsFromCache() (map[string]flag.Flag, error)
- func (g *GoFeatureFlag) IntVariation(flagKey string, ctx ffcontext.Context, defaultValue int) (int, error)
- func (g *GoFeatureFlag) IntVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue int) (model.VariationResult[int], error)
- func (g *GoFeatureFlag) JSONArrayVariation(flagKey string, ctx ffcontext.Context, defaultValue []interface{}) ([]interface{}, error)
- func (g *GoFeatureFlag) JSONArrayVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue []interface{}) (model.VariationResult[[]interface{}], error)
- func (g *GoFeatureFlag) JSONVariation(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}) (map[string]interface{}, error)
- func (g *GoFeatureFlag) JSONVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}) (model.VariationResult[map[string]interface{}], error)
- func (g *GoFeatureFlag) RawVariation(flagKey string, ctx ffcontext.Context, sdkDefaultValue interface{}) (model.RawVarResult, error)
- func (g *GoFeatureFlag) StringVariation(flagKey string, ctx ffcontext.Context, defaultValue string) (string, error)
- func (g *GoFeatureFlag) StringVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue string) (model.VariationResult[string], error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllFlagsState ¶ added in v0.17.0
AllFlagsState return the values of all the flags for a specific user. If valid field is false it means that we had an error when checking the flags.
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 BoolVariationDetails ¶ added in v1.1.0
func BoolVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue bool) ( model.VariationResult[bool], error)
BoolVariationDetails return the details of the evaluation for boolean flag. 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 float64. 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 Float64VariationDetails ¶ added in v1.1.0
func Float64VariationDetails(flagKey string, ctx ffcontext.Context, defaultValue float64, ) (model.VariationResult[float64], error)
Float64VariationDetails return the details of the evaluation for float64 flag. 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 GetCacheRefreshDate ¶ added in v0.22.0
GetCacheRefreshDate gives the date of the latest refresh of the cache
func GetFlagsFromCache ¶ added in v0.24.0
GetFlagsFromCache returns all the flags present in the cache with their current state when calling this method. If cache hasn't been initialized, an error reporting this is returned.
func Init ¶
Init the feature flag component with the configuration of ffclient.Config
func main() { err := ffclient.Init(ffclient.Config{ PollingInterval: 3 * time.Second, Retriever: &httpretriever.Retriever{ URL: "http://example.com/flag-config.yaml", }, }) defer ffclient.Close()
func IntVariation ¶
IntVariation return the value of the flag in int. 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 IntVariationDetails ¶ added in v1.1.0
func IntVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue int) (model.VariationResult[int], error)
IntVariationDetails return the details of the evaluation for int flag. 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, ctx ffcontext.Context, defaultValue []interface{}) ([]interface{}, error)
JSONArrayVariation return the value of the flag in []interface{}. 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 JSONArrayVariationDetails ¶ added in v1.1.0
func JSONArrayVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue []interface{}, ) (model.VariationResult[[]interface{}], error)
JSONArrayVariationDetails return the details of the evaluation for []interface{} flag. 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, ctx ffcontext.Context, defaultValue map[string]interface{}, ) (map[string]interface{}, error)
JSONVariation return the value of the flag in map[string]interface{}. 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 JSONVariationDetails ¶ added in v1.1.0
func JSONVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}, ) (model.VariationResult[map[string]interface{}], error)
JSONVariationDetails return the details of the evaluation for map[string]interface{} flag. 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 string. 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 StringVariationDetails ¶ added in v1.1.0
func StringVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue string, ) (model.VariationResult[string], error)
StringVariationDetails return the details of the evaluation for string flag. 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 { // PollingInterval (optional) Poll every X time // The minimum possible is 1 second // Default: 60 seconds PollingInterval time.Duration // EnablePollingJitter (optional) set to true if you want to avoid having true periodicity when // retrieving your flags. It is useful to avoid having spike on your flag configuration storage // in case your application is starting multiple instance at the same time. // We ensure a deviation that is maximum + or - 10% of your polling interval. // Default: false EnablePollingJitter bool // Logger (optional) logger use by the library // Default: No log Logger *log.Logger // Context (optional) used to call other services (HTTP, S3 ...) // Default: context.Background() Context context.Context // Environment (optional), can be checked in feature flag rules // Default: "" Environment string // Retriever is the component in charge to retrieve your flag file Retriever retriever.Retriever // Retrievers is the list of components in charge to retrieving your flag files. // We are dealing with config files in order, if you have the same flag name in multiple files it will be override // based of the order of the retrievers in the slice. // // Note: If both Retriever and Retrievers are set, we will start by calling the Retriever and, // after we will use the order of Retrievers. Retrievers []retriever.Retriever // Notifiers (optional) is the list of notifiers called when a flag change Notifiers []notifier.Notifier // FileFormat (optional) is the format of the file to retrieve (available YAML, TOML and JSON) // Default: YAML FileFormat string // DataExporter (optional) is the configuration where we store how we should output the flags variations results DataExporter DataExporter // StartWithRetrieverError (optional) If true, the SDK will start even if we did not get any flags from the retriever. // It will serve only default values until all the retrievers returns the flags. // The init method will not return any error if the flag file is unreachable. // Default: false StartWithRetrieverError bool // Offline (optional) If true, the SDK will not try to retrieve the flag file and will not export any data. // No notification will be sent neither. // Default: false Offline bool }
Config is the configuration of go-feature-flag. You should also have a retriever to specify where to read the flags file.
type DataExporter ¶ added in v0.10.0
type DataExporter struct { // FlushInterval is the interval we are waiting to export the data. // example: if you set your FlushInterval to 1 minutes, we will send // the data every minute unless we reach the max event in cache before. FlushInterval time.Duration // MaxEventInMemory is the maximum number of event you keep in the cache // before sending the data to the Exporter. // We will send the data when the MaxEventInMemory is reach or if we have // waited the FlushInterval. MaxEventInMemory int64 // Exporter is the configuration of your exporter. // You can see all available exporter in the exporter package. Exporter exporter.Exporter }
DataExporter is the configuration of your export target.
type GoFeatureFlag ¶ added in v0.6.0
type GoFeatureFlag struct {
// contains filtered or unexported fields
}
GoFeatureFlag is the main object of the library it contains the cache, the config and the update.
func New ¶ added in v0.6.0
func New(config Config) (*GoFeatureFlag, error)
New creates a new go-feature-flag instance that retrieve the config from a YAML file and return everything you need to manage your flags.
func (*GoFeatureFlag) AllFlagsState ¶ added in v0.17.0
func (g *GoFeatureFlag) AllFlagsState(ctx ffcontext.Context) flagstate.AllFlags
AllFlagsState return a flagstate.AllFlags that contains all the flags for a specific user.
func (*GoFeatureFlag) BoolVariation ¶ added in v0.6.0
func (g *GoFeatureFlag) BoolVariation(flagKey string, ctx ffcontext.Context, defaultValue bool) (bool, error)
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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) BoolVariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) BoolVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue bool, ) (model.VariationResult[bool], error)
BoolVariationDetails return the details of the evaluation for boolean flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) Close ¶ added in v0.6.0
func (g *GoFeatureFlag) Close()
Close wait until thread are done
func (*GoFeatureFlag) CollectEventData ¶ added in v1.7.0
func (g *GoFeatureFlag) CollectEventData(event exporter.FeatureEvent)
CollectEventData is collecting events and sending them to the data exporter to be stored.
func (*GoFeatureFlag) Float64Variation ¶ added in v0.6.0
func (g *GoFeatureFlag) Float64Variation(flagKey string, ctx ffcontext.Context, defaultValue float64) (float64, error)
Float64Variation return the value of the flag in float64. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) Float64VariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) Float64VariationDetails(flagKey string, ctx ffcontext.Context, defaultValue float64, ) (model.VariationResult[float64], error)
Float64VariationDetails return the details of the evaluation for float64 flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) GetCacheRefreshDate ¶ added in v0.22.0
func (g *GoFeatureFlag) GetCacheRefreshDate() time.Time
GetCacheRefreshDate gives the date of the latest refresh of the cache
func (*GoFeatureFlag) GetFlagsFromCache ¶ added in v0.24.0
func (g *GoFeatureFlag) GetFlagsFromCache() (map[string]flag.Flag, error)
GetFlagsFromCache returns all the flags present in the cache with their current state when calling this method. If cache hasn't been initialized, an error reporting this is returned.
func (*GoFeatureFlag) IntVariation ¶ added in v0.6.0
func (g *GoFeatureFlag) IntVariation(flagKey string, ctx ffcontext.Context, defaultValue int) (int, error)
IntVariation return the value of the flag in int. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) IntVariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) IntVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue int, ) (model.VariationResult[int], error)
IntVariationDetails return the details of the evaluation for int flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) JSONArrayVariation ¶ added in v0.6.0
func (g *GoFeatureFlag) JSONArrayVariation( flagKey string, ctx ffcontext.Context, defaultValue []interface{}, ) ([]interface{}, error)
JSONArrayVariation return the value of the flag in []interface{}. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) JSONArrayVariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) JSONArrayVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue []interface{}, ) (model.VariationResult[[]interface{}], error)
JSONArrayVariationDetails return the details of the evaluation for []interface{} flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) JSONVariation ¶ added in v0.6.0
func (g *GoFeatureFlag) JSONVariation( flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}, ) (map[string]interface{}, error)
JSONVariation return the value of the flag in map[string]interface{}. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) JSONVariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) JSONVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue map[string]interface{}, ) (model.VariationResult[map[string]interface{}], error)
JSONVariationDetails return the details of the evaluation for []interface{} flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) RawVariation ¶ added in v0.22.2
func (g *GoFeatureFlag) RawVariation(flagKey string, ctx ffcontext.Context, sdkDefaultValue interface{}, ) (model.RawVarResult, error)
RawVariation return the raw value of the flag (without any types). This raw result is mostly used by software built on top of go-feature-flag such as go-feature-flag relay proxy. If you are using directly the library you should avoid calling this function. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) StringVariation ¶ added in v0.6.0
func (g *GoFeatureFlag) StringVariation(flagKey string, ctx ffcontext.Context, defaultValue string) (string, error)
StringVariation return the value of the flag in string. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
func (*GoFeatureFlag) StringVariationDetails ¶ added in v1.1.0
func (g *GoFeatureFlag) StringVariationDetails(flagKey string, ctx ffcontext.Context, defaultValue string, ) (model.VariationResult[string], error)
StringVariationDetails return the details of the evaluation for string flag. 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. Note: Use this function only if you are using multiple go-feature-flag instances.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
relayproxy/docs
Package docs Code generated by swaggo/swag.
|
Package docs Code generated by swaggo/swag. |
examples
|
|
Package exporter defines the data exporter of go-feature-flag
|
Package exporter defines the data exporter of go-feature-flag |
Package ffuser defines the go-feature-flag model for user properties.
|
Package ffuser defines the go-feature-flag model for user properties. |
Package testutils is a generated GoMock package.
|
Package testutils is a generated GoMock package. |
utils
|
|