{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package generic\n\n## Types\n\n```go\ntype FlagRow struct {\n\tKey         string    `json:\"key\"`\n\tType        string    `json:\"type\"`\n\tDescription string    `json:\"description\"`\n\tEnabled     bool      `json:\"enabled\"`\n\tDefaultVal  string    `json:\"default_val\"`\n\tTags        []string  `json:\"tags\"`\n\tPercentage  float64   `json:\"percentage\"`\n\tCreatedAt   time.Time `json:\"created_at\"`\n\tUpdatedAt   time.Time `json:\"updated_at\"`\n}\n```\nFlagRow represents a row in the feature\\_flags table.\n\n```go\ntype OverrideRow struct {\n\tID       int64  `json:\"id\"`\n\tFlagKey  string `json:\"flag_key\"`\n\tScope    string `json:\"scope\"`     // \"user\" or \"group\"\n\tScopeKey string `json:\"scope_key\"` // user ID or group name\n\tValue    string `json:\"value\"`\n}\n```\nOverrideRow represents a flag override for a specific user or group.\n\n```go\ntype Provider struct {\n\t// contains filtered or unexported fields\n}\n```\nProvider is the built-in generic feature-flag provider. Flag definitions, targeting rules, and overrides are stored in a SQLite database.\n\nEvaluation order:\n\n 1. Disabled check -\u003e return default value\n 2. User overrides (scope=\"user\", scope\\_key=UserKey)\n 3. Group overrides (scope=\"group\", matched via \"groups\" attribute)\n 4. Targeting rules (evaluated top-to-bottom by priority)\n 5. Percentage rollout (deterministic hash of userKey+flagKey)\n 6. Default value\n\n```go\nfunc NewProvider(store *Store, logger *slog.Logger) *Provider\n```\nNewProvider creates a generic provider backed by the given store.\n\n```go\nfunc (p *Provider) AllFlags(ctx context.Context, evalCtx featureflag.EvaluationContext) ([]featureflag.FlagValue, error)\n```\nAllFlags implements featureflag.Provider.\n\n```go\nfunc (p *Provider) Evaluate(ctx context.Context, key string, evalCtx featureflag.EvaluationContext) (featureflag.FlagValue, error)\n```\nEvaluate implements featureflag.Provider. It resolves the flag through the six-step evaluation order documented on the Provider type.\n\n```go\nfunc (p *Provider) Name() string\n```\nName implements featureflag.Provider.\n\n```go\nfunc (p *Provider) NotifyChange(key string, value any, flagType featureflag.FlagType)\n```\nNotifyChange should be called after mutating a flag (e.g., from the admin API) to inform subscribers of the change.\n\n```go\nfunc (p *Provider) Subscribe(fn func(featureflag.FlagChangeEvent)) (cancel func())\n```\nSubscribe implements featureflag.Provider.\n\n```go\ntype RuleRow struct {\n\tID         int64  `json:\"id\"`\n\tFlagKey    string `json:\"flag_key\"`\n\tPriority   int    `json:\"priority\"`\n\tAttribute  string `json:\"attribute\"`\n\tOperator   string `json:\"operator\"`\n\tValue      string `json:\"value\"`\n\tServeValue string `json:\"serve_value\"`\n}\n```\nRuleRow represents a targeting rule row.\n\n```go\ntype Store struct {\n\t// contains filtered or unexported fields\n}\n```\nStore persists flag definitions, targeting rules, and overrides in SQLite.\n\n```go\nfunc NewStore(dbPath string) (*Store, error)\n```\nNewStore opens (or creates) a SQLite database at the given path and ensures the schema tables exist.\n\n```go\nfunc NewStoreFromDB(db *sql.DB) (*Store, error)\n```\nNewStoreFromDB wraps an existing \\*sql.DB (useful for testing).\n\n```go\nfunc (s *Store) AddRule(ctx context.Context, r *RuleRow) error\n```\nAddRule inserts a new targeting rule.\n\n```go\nfunc (s *Store) Close() error\n```\nClose closes the underlying database connection.\n\n```go\nfunc (s *Store) DeleteFlag(ctx context.Context, key string) error\n```\nDeleteFlag removes a flag and its related rules and overrides (cascade).\n\n```go\nfunc (s *Store) DeleteOverride(ctx context.Context, id int64) error\n```\nDeleteOverride removes an override by ID.\n\n```go\nfunc (s *Store) DeleteRule(ctx context.Context, id int64) error\n```\nDeleteRule removes a targeting rule by ID.\n\n```go\nfunc (s *Store) GetFlag(ctx context.Context, key string) (*FlagRow, error)\n```\nGetFlag retrieves a single flag definition by key.\n\n```go\nfunc (s *Store) GetOverrides(ctx context.Context, flagKey string) ([]OverrideRow, error)\n```\nGetOverrides returns all overrides for a flag.\n\n```go\nfunc (s *Store) GetRules(ctx context.Context, flagKey string) ([]RuleRow, error)\n```\nGetRules returns all targeting rules for a flag, ordered by priority ascending.\n\n```go\nfunc (s *Store) ListFlags(ctx context.Context) ([]FlagRow, error)\n```\nListFlags returns all flag definitions.\n\n```go\nfunc (s *Store) UpsertFlag(ctx context.Context, f *FlagRow) error\n```\nUpsertFlag creates or updates a flag definition.\n\n```go\nfunc (s *Store) UpsertOverride(ctx context.Context, o *OverrideRow) error\n```\nUpsertOverride creates or updates an override.\n\n","path":"github.com/GoCodeAlone/workflow/featureflag/generic","name":"generic","synopsis":"","isRedistributable":true}
