features

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 12 Imported by: 0

README

features-go

Go Reference

Feature Flags Go client.

Install

go get github.com/altipla-consulting/features-go

Usage

Configure features (single project)

To configure features, run Configure with the server URL and the project corresponding to the flags.

func main() {
  features.Configure("https://youserver.com", "project")
}
Check feature flag is enabled
if features.Flag("feature") {
    fmt.Print("Feature flag is enabled.")
}
Check feature flag is enabled with tenant
if features.Flag("feature", features.WithTenant("tenant")) {
    fmt.Print("Feature flag is enabled with tenant.")
}
Multiple projects (connector / intermediary)

When the same process evaluates flags for several projects, use a Pool. It creates one client per project on first use and reuses it afterwards, so the in-memory cache and background sync are preserved across calls.

pool := features.NewPool("https://youserver.com", features.WithLogger(log))

if pool.Flag(project, "feature", features.WithTenant(tenant)) {
    fmt.Print("Feature flag is enabled.")
}

Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using make gofmt.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient *featuresClient

Functions

func Configure

func Configure(serverURL, project string, opts ...ConfigureOption)

Configure initializes the default feature client with the provided server URL and project, and starts a background synchronization process.

func Flag

func Flag(code string, opts ...FlagOption) bool

Flag returns true if the flag is enabled with the given options.

Types

type ConfigureOption added in v0.2.0

type ConfigureOption func(*configureOptions)

func WithDisableStats added in v0.2.0

func WithDisableStats(disabled bool) ConfigureOption

func WithLogger added in v0.2.0

func WithLogger(logger *slog.Logger) ConfigureOption

type FlagOption

type FlagOption func(*flagOptions)

func WithTenant

func WithTenant(tenant string) FlagOption

WithTenant sets the tenant for the flag.

type Pool added in v0.3.0

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

Pool manages feature clients keyed by project for the same server URL. Concurrent calls for the same project reuse the same Client and its cache.

func NewPool added in v0.3.0

func NewPool(serverURL string, opts ...ConfigureOption) *Pool

NewPool creates a pool that lazily builds clients for each project.

func (*Pool) Client added in v0.3.0

func (p *Pool) Client(project string) *featuresClient

Client returns the cached client for project, creating it on first use.

func (*Pool) Close added in v0.3.0

func (p *Pool) Close()

Close closes all clients in the pool.

func (*Pool) Flag added in v0.3.0

func (p *Pool) Flag(project, code string, opts ...FlagOption) bool

Flag evaluates a flag for the given project.

Jump to

Keyboard shortcuts

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