feature

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package feature resolves plan defaults and tenant-level feature overrides.

Index

Constants

View Source
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
)
View Source
const (
	// DefaultSQLTableName is the default feature flag table name.
	DefaultSQLTableName = "saas_feature_flags"
)

Variables

View Source
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 Flag

type Flag struct {
	Key     string
	Enabled bool
	Config  map[string]string
}

Flag describes a feature flag.

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

func (store *MemoryStore) SetPlanDefaults(ctx context.Context, planID string, flags []Flag) error

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

type SQLDialect = sqlutil.Dialect

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

func (store *SQLStore) SetPlanDefaults(ctx context.Context, planID string, flags []Flag) error

SetPlanDefaults replaces default flags for a plan.

func (*SQLStore) SetTenantOverrides added in v0.1.6

func (store *SQLStore) SetTenantOverrides(ctx context.Context, tenantID types.TenantID, flags []Flag) error

SetTenantOverrides replaces tenant-level overrides.

type SQLStoreOption added in v0.1.6

type SQLStoreOption func(*SQLStore) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL