Documentation
¶
Overview ¶
Package featureflag provides a comprehensive feature flag library for Go applications. This package offers a simple, single-import interface to all feature flag functionality including multiple storage backends, caching, observability, and flexible configuration.
Basic usage:
import "github.com/ajeet-kumar1087/go-feature-flag"
// Create a client with default settings (memory storage, caching enabled)
client, err := featureflag.NewClient(featureflag.DefaultConfig())
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Create and set a feature flag
flag := featureflag.FeatureFlag{
Key: "new-feature",
Enabled: true,
Description: "Enable new feature",
}
client.SetFlag(ctx, flag)
// Check if feature is enabled
if enabled, _ := client.IsEnabled(ctx, "new-feature"); enabled {
// Use new feature
}
Advanced usage with custom configuration:
config := featureflag.Config{
Storage: featureflag.StorageConfig{
Type: "redis",
Redis: &featureflag.RedisConfig{
Addr: "localhost:6379",
},
},
Cache: featureflag.CacheConfig{
Enabled: true,
TTL: featureflag.Duration(10 * time.Minute),
MaxSize: 1000,
},
}
client, err := featureflag.NewClient(config)
Index ¶
- Constants
- Variables
- func IsNotFoundError(err error) bool
- func IsRetryableError(err error) bool
- func NewCache(maxSize int, ttl time.Duration) *cache.Cache
- type CacheConfig
- type Client
- type Config
- type Duration
- type ErrorType
- type FeatureFlag
- type FeatureFlagError
- type MetricsSnapshot
- type ObservabilityConfig
- type PostgresConfig
- type RedisConfig
- type StorageConfig
- type Store
Constants ¶
const ( ErrorTypeNotFound = core.ErrorTypeNotFound ErrorTypeValidation = core.ErrorTypeValidation ErrorTypeStorage = core.ErrorTypeStorage ErrorTypeCache = core.ErrorTypeCache ErrorTypeConnection = core.ErrorTypeConnection ErrorTypeTimeout = core.ErrorTypeTimeout ErrorTypeAuth = core.ErrorTypeAuth ErrorTypeRateLimit = core.ErrorTypeRateLimit ErrorTypeClient = core.ErrorTypeClient ErrorTypeInternal = core.ErrorTypeInternal )
Error type constants
Variables ¶
var ( // ErrFlagNotFound indicates a feature flag was not found ErrFlagNotFound = core.ErrFlagNotFound // ErrInvalidFlag indicates an invalid feature flag ErrInvalidFlag = core.ErrInvalidFlag // ErrStorageFailure indicates a storage operation failed ErrStorageFailure = core.ErrStorageFailure // ErrInvalidConfig indicates invalid configuration ErrInvalidConfig = core.ErrInvalidConfig // ErrClientClosed indicates the client is closed ErrClientClosed = core.ErrClientClosed // ErrConnectionFailure indicates a connection failure ErrConnectionFailure = core.ErrConnectionFailure // ErrTimeout indicates an operation timeout ErrTimeout = core.ErrTimeout )
Common error variables
Functions ¶
func IsNotFoundError ¶
IsNotFoundError checks if an error is a "not found" error.
func IsRetryableError ¶
IsRetryableError checks if an error indicates a retryable operation.
Types ¶
type Client ¶
Client is the main interface for feature flag operations
func NewClient ¶
NewClient creates a new feature flag client with the given configuration. This is the main entry point for using the feature flag library.
func NewClientWithDefaults ¶
NewClientWithDefaults creates a new feature flag client with default configuration. Uses in-memory storage with caching enabled - suitable for development and testing.
type Config ¶
Config holds all configuration options for the feature flag library
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a configuration with sensible defaults. Uses in-memory storage, caching enabled, and observability disabled.
type ErrorType ¶
ErrorType represents different categories of errors
func ClassifyError ¶
ClassifyError determines the error type based on the underlying error.
type FeatureFlag ¶
type FeatureFlag = core.FeatureFlag
FeatureFlag represents a feature flag with metadata and validation
type FeatureFlagError ¶
type FeatureFlagError = core.FeatureFlagError
FeatureFlagError provides detailed error information
type MetricsSnapshot ¶
type MetricsSnapshot = core.MetricsSnapshot
MetricsSnapshot provides a point-in-time view of metrics
type ObservabilityConfig ¶
type ObservabilityConfig = config.ObservabilityConfig
ObservabilityConfig defines logging and metrics configuration
type PostgresConfig ¶
type PostgresConfig = config.PostgresConfig
PostgresConfig defines PostgreSQL-specific configuration
type RedisConfig ¶
type RedisConfig = config.RedisConfig
RedisConfig defines Redis-specific configuration
type StorageConfig ¶
type StorageConfig = config.StorageConfig
StorageConfig defines storage backend configuration
type Store ¶
Store defines the interface for feature flag storage backends
func NewCachedStore ¶
func NewCachedStore(store Store, cacheConfig CacheConfig) Store
NewCachedStore creates a cached store wrapper around any store implementation. Improves performance by caching frequently accessed feature flags.
func NewMemoryStore ¶
func NewMemoryStore() Store
NewMemoryStore creates a new memory-based feature flag store. Suitable for development, testing, and single-instance deployments.
func NewPostgresStore ¶
func NewPostgresStore(cfg *PostgresConfig) (Store, error)
NewPostgresStore creates a new PostgreSQL-based feature flag store. Suitable for production deployments requiring ACID compliance and complex queries.
func NewRedisStore ¶
func NewRedisStore(cfg *RedisConfig) (Store, error)
NewRedisStore creates a new Redis-based feature flag store. Suitable for production deployments requiring persistence and scalability.