flags

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package flags provides a thin REST client over the nself feature-flags plugin (port 3305, nginx-proxied). All requests go through the nginx route so no direct port access is ever used.

Package flags — flag lifecycle helpers (sunset and removal date enforcement).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLifecycleDisable added in v1.0.16

func ApplyLifecycleDisable(flags []Flag, now time.Time) int

ApplyLifecycleDisable mutates the flags slice in place: any flag whose RemovalDate has passed is force-disabled (Enabled=false). Returns the number of flags that were disabled.

Types

type AuditEntry

type AuditEntry struct {
	ID      string          `json:"id"`
	FlagKey string          `json:"flag_key"`
	Actor   string          `json:"actor"`
	Action  string          `json:"action"`
	Before  json.RawMessage `json:"before"`
	After   json.RawMessage `json:"after"`
	Reason  *string         `json:"reason"`
	Ts      time.Time       `json:"ts"`
}

AuditEntry is a row from np_feature_flags_audit.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a thin REST client for the feature-flags plugin.

func NewClient

func NewClient(baseURL string) *Client

NewClient returns a Client routed through the local nginx proxy (port 3305). Callers should rely on the default URL; override only in tests.

func (*Client) Disable

func (c *Client) Disable(ctx context.Context, key string) (*Flag, error)

Disable sets a flag to enabled=false and broadcasts pubsub invalidation.

func (*Client) Enable

func (c *Client) Enable(ctx context.Context, key string) (*Flag, error)

Enable sets a flag to enabled=true.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (*Flag, error)

Get returns a single flag by key.

func (*Client) History

func (c *Client) History(ctx context.Context, key string) ([]AuditEntry, error)

History returns the audit log for a single flag.

func (*Client) Kill

func (c *Client) Kill(ctx context.Context, key, reason string) (*Flag, error)

Kill performs an emergency kill-switch on a flag. reason is required.

func (*Client) List

func (c *Client) List(ctx context.Context, flagType string) ([]Flag, error)

List returns all feature flags, optionally filtered by type.

func (*Client) Prune

func (c *Client) Prune(ctx context.Context, dryRun bool) ([]Flag, error)

Prune lists flags that have exceeded their stale_after_days threshold. When dryRun is true, no flags are deleted.

func (*Client) Set

func (c *Client) Set(ctx context.Context, key string, req SetFlagRequest) (*Flag, error)

Set updates a flag's enabled state and/or rollout percentage.

type Flag

type Flag struct {
	ID           string          `json:"id"`
	Key          string          `json:"key"`
	Name         *string         `json:"name"`
	Description  *string         `json:"description"`
	Type         string          `json:"type"`
	Enabled      bool            `json:"enabled"`
	RolloutPct   *int            `json:"rollout_pct"`
	DefaultValue json.RawMessage `json:"default_value"`
	Rules        json.RawMessage `json:"rules"`
	SunsetAt     *time.Time      `json:"sunset_at,omitempty"`
	RemovalDate  *time.Time      `json:"removal_date,omitempty"`
	CreatedAt    time.Time       `json:"created_at"`
	UpdatedAt    time.Time       `json:"updated_at"`
}

Flag is a feature flag as returned by the plugin API.

type KillRequest

type KillRequest struct {
	Reason string `json:"reason"`
}

KillRequest is the body for the kill operation.

type LifecycleWarning added in v1.0.16

type LifecycleWarning struct {
	FlagKey string
	Level   string // "warn" or "error"
	Message string
}

LifecycleWarning describes a sunset/removal enforcement event for a flag.

func CheckFlagLifecycle added in v1.0.16

func CheckFlagLifecycle(flags []Flag, now time.Time) []LifecycleWarning

CheckFlagLifecycle inspects each flag's SunsetAt and RemovalDate fields against the supplied "now" timestamp and returns warnings for flags that are past sunset (level=warn) or past removal (level=error).

A flag with no SunsetAt/RemovalDate produces no warning. A flag with SunsetAt in the future produces no warning.

type SetFlagRequest

type SetFlagRequest struct {
	Enabled    *bool   `json:"enabled,omitempty"`
	RolloutPct *int    `json:"rollout_pct,omitempty"`
	Reason     *string `json:"reason,omitempty"`
}

SetFlagRequest is the body for the set/update operation.

Jump to

Keyboard shortcuts

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