Documentation
¶
Overview ¶
Package feature resolves plan defaults and tenant-level feature overrides.
Index ¶
- Constants
- Variables
- type Flag
- type MemoryStore
- func (store *MemoryStore) List(ctx context.Context, tenantID types.TenantID, planID string) ([]Flag, error)
- func (store *MemoryStore) Resolve(ctx context.Context, tenantID types.TenantID, planID string, key string) (Flag, error)
- func (store *MemoryStore) SetPlanDefaults(ctx context.Context, planID string, flags []Flag) error
- func (store *MemoryStore) SetTenantOverrides(ctx context.Context, tenantID types.TenantID, flags []Flag) error
- type SQLDialect
- type SQLStore
- func (store *SQLStore) List(ctx context.Context, tenantID types.TenantID, planID string) ([]Flag, error)
- func (store *SQLStore) Resolve(ctx context.Context, tenantID types.TenantID, planID string, key string) (Flag, error)
- func (store *SQLStore) SetPlanDefaults(ctx context.Context, planID string, flags []Flag) error
- func (store *SQLStore) SetTenantOverrides(ctx context.Context, tenantID types.TenantID, flags []Flag) error
- type SQLStoreOption
- type Store
Constants ¶
const ( // SQLDialectMySQL uses question-mark placeholders and is the default. SQLDialectMySQL = sqlutil.DialectMySQL // SQLDialectSQLite uses question-mark placeholders. SQLDialectSQLite = sqlutil.DialectSQLite // SQLDialectPostgres uses numbered placeholders. SQLDialectPostgres = sqlutil.DialectPostgres )
const (
// DefaultSQLTableName is the default feature flag table name.
DefaultSQLTableName = "saas_feature_flags"
)
Variables ¶
var ( // ErrInvalidFeature reports invalid feature input. ErrInvalidFeature = errors.New("gotenancy/feature: invalid feature") // ErrFeatureNotFound reports a missing feature flag. ErrFeatureNotFound = errors.New("gotenancy/feature: feature not found") // ErrNilDB reports that a SQL store was created with a nil database handle. ErrNilDB = errors.New("gotenancy/feature: nil db") // ErrInvalidTableName reports an unsafe SQL table name. ErrInvalidTableName = errors.New("gotenancy/feature: invalid table name") // ErrUnsupportedSQLDialect reports an unsupported SQLStore dialect. ErrUnsupportedSQLDialect = errors.New("gotenancy/feature: unsupported sql dialect") )
Functions ¶
This section is empty.
Types ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore stores feature flags in memory.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates an empty feature store.
func (*MemoryStore) List ¶
func (store *MemoryStore) List(ctx context.Context, tenantID types.TenantID, planID string) ([]Flag, error)
List returns merged feature flags.
func (*MemoryStore) Resolve ¶
func (store *MemoryStore) Resolve(ctx context.Context, tenantID types.TenantID, planID string, key string) (Flag, error)
Resolve returns the tenant override when present, otherwise the plan default.
func (*MemoryStore) SetPlanDefaults ¶
SetPlanDefaults replaces default flags for a plan.
func (*MemoryStore) SetTenantOverrides ¶
func (store *MemoryStore) SetTenantOverrides(ctx context.Context, tenantID types.TenantID, flags []Flag) error
SetTenantOverrides replaces tenant-level overrides.
type SQLDialect ¶ added in v0.1.6
SQLDialect controls SQL placeholder rendering for SQLStore.
type SQLStore ¶ added in v0.1.6
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore persists plan feature defaults and tenant overrides through database/sql.
The table is expected to contain these columns: scope, owner_id, key, enabled, config. Use a unique key on (scope, owner_id, key). The config column stores a JSON object.
func NewSQLStore ¶ added in v0.1.6
func NewSQLStore(db *sql.DB, opts ...SQLStoreOption) (*SQLStore, error)
NewSQLStore creates a SQL-backed feature store.
func (*SQLStore) List ¶ added in v0.1.6
func (store *SQLStore) List(ctx context.Context, tenantID types.TenantID, planID string) ([]Flag, error)
List returns merged feature flags.
func (*SQLStore) Resolve ¶ added in v0.1.6
func (store *SQLStore) Resolve(ctx context.Context, tenantID types.TenantID, planID string, key string) (Flag, error)
Resolve returns the tenant override when present, otherwise the plan default.
func (*SQLStore) SetPlanDefaults ¶ added in v0.1.6
SetPlanDefaults replaces default flags for a plan.
type SQLStoreOption ¶ added in v0.1.6
SQLStoreOption configures SQLStore.
func WithSQLDialect ¶ added in v0.1.6
func WithSQLDialect(dialect SQLDialect) SQLStoreOption
WithSQLDialect configures SQL placeholder rendering.
func WithTableName ¶ added in v0.1.6
func WithTableName(table string) SQLStoreOption
WithTableName overrides the default feature flag table name.
type Store ¶
type Store interface {
SetPlanDefaults(ctx context.Context, planID string, flags []Flag) error
SetTenantOverrides(ctx context.Context, tenantID types.TenantID, flags []Flag) error
Resolve(ctx context.Context, tenantID types.TenantID, planID string, key string) (Flag, error)
List(ctx context.Context, tenantID types.TenantID, planID string) ([]Flag, error)
}
Store persists plan defaults and tenant overrides.