Documentation
¶
Overview ¶
A package for retreiving feature flags from a dynamo document.
Retrieving a boolean flag:
s, err := flagship.New(context.Background(), flagship.WithTableName(tableName)) if err != nil { t.Errorf("unexpected error got %v", err) } if s.Bool(context.Background(), "newfeature") { // New Code } else { // Old code }
Index ¶
- func GetHash(ctx context.Context, key string, hashKey io.Reader) uint
- type BoolFeatureStore
- type FeatureStore
- type Option
- func WithClient(client *dynamodb.Client) Option
- func WithClock(clock func() time.Time) Option
- func WithLogger(logger *log.Logger) Option
- func WithRecordName(recordName string) Option
- func WithRegion(region string) Option
- func WithTTL(ttl time.Duration) Option
- func WithTableName(tableName string) Option
- type ThrottleFeatureStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BoolFeatureStore ¶ added in v0.0.3
type BoolFeatureStore interface { // Bool returns the state of the feature flag with the key of `key`: // If the feature is missing from the table then always returns false. // Example: // { // "features": { // "newFeature": true // } // } // if s.Bool(context.Background(), "newfeature") { // // New Code // } else { // // Old code // } Bool(ctx context.Context, key string) bool // All returns the state containing all feature flags AllBools(ctx context.Context) map[string]bool }
BoolFeatureStore defines the interface for accessing boolean typed feature flags from some source.
type FeatureStore ¶
type FeatureStore interface { BoolFeatureStore ThrottleFeatureStore }
FeatureStore is an aggregate interface for accessing all supported types of feature flag.
type Option ¶
type Option func(*featureStoreConfig)
Option is a function that can modify internal config.
func WithClient ¶
WithClient allows modification of the dynamo client used. The default value is constructed using default credentials.
s, err := flagship.New(context.Background(), flagship.WithClient(client))
func WithClock ¶
WithClock allows the overriding of the function used to get current time. The default value will be `time.Now`.
s, err := flagship.New(context.Background(), flagship.WithClock(func() time.Time { return time.Time{} }))
func WithLogger ¶ added in v0.0.14
WithLogger allows the logging of flagship internals The default value is nil
s, err := flagship.New(context.Background(), flagship.WithLogger(logger))
func WithRecordName ¶
WithRecordName allows modification of the AWS DynamoDB partition key. The default value is "features".
s, err := flagship.New(context.Background(), flagship.WithRecordName("features1"))
func WithRegion ¶
WithRegion allows modification of the AWS Region in which the dynamo table resides. The default value will rely on the AWS Go SDK to find the correct region.
s, err := flagship.New(context.Background(), flagship.WithRegion("eu-west-1"))
func WithTTL ¶
WithTTL allows modification of the cache expiry for features. The default value is 30 seconds.
s, err := flagship.New(context.Background(), flagship.WithTTL(1 * time.Hour))
func WithTableName ¶
WithTableName allows modification of the AWS DynamoDB table name. The default value is "featureFlagStore".
s, err := flagship.New(context.Background(), flagship.WithTableName("feature-table"))
type ThrottleFeatureStore ¶ added in v0.0.3
type ThrottleFeatureStore interface { // ThrottleAllow returns whether a given hash key is bucketed. // If the feature is missing from the table then always returns false. // Example: // { // "throttles": { // "newThrottleFeature": { // // whitelist is an optional list of hashes that will always be bucketed. // "whitelist":[10, 3321], // // probability is the likelihood that a hash is bucketed as a percentage. // // value is truncated to 2dp // "probability": 2.5 // // forceRejectAll is an optional flag to force the rejection of all the traffic // "forceRejectAll": true // } // } // } // if s.ThrottleAllow(context.Background(), "newThrottleFeature", strings.NewReader("some hash")) { // // New Code // } else { // // Old code // } ThrottleAllow(ctx context.Context, key string, hashKey io.Reader) bool // GetHash returns the hash that would be bucketed in ThrottleAllow: // h := s.GetHash(context.Background(), "newThrottleFeature", strings.NewReader("some hash")) { GetHash(ctx context.Context, key string, hashKey io.Reader) uint }
ThrottleFeatureStore defines the interface for accessing a feature flag that needs bucketing.