feature

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package feature provides mechanisms for version-gated feature mutations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutation

type Mutation[T any] struct {
	// Name is a human-readable identifier for the mutation, used for error reporting.
	Name string
	// Feature determines whether the mutation should be applied.
	Feature *ResourceFeature
	// Mutate is the function that applies the changes to the object.
	Mutate func(T) error
}

Mutation defines a mutation that is applied to an object of type T only if its associated ResourceFeature is enabled.

func (*Mutation[T]) ApplyIntent

func (m *Mutation[T]) ApplyIntent(obj T) error

ApplyIntent applies the mutation intent on the provided object if the feature is enabled. If the feature is nil or disabled, it returns nil without performing any action. If the mutation is enabled but the Mutate function is nil, it returns an error.

type ResourceFeature

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

ResourceFeature represents the conditions under which a feature mutation applies.

A ResourceFeature is enabled only when all registered semver constraints match the current version and all additional truth conditions added via When are true.

func NewResourceFeature

func NewResourceFeature(currentVersion string, versionConstraints []VersionConstraint) *ResourceFeature

NewResourceFeature creates a new ResourceFeature for the given current version and semver constraints.

Nil constraints are ignored.

func (*ResourceFeature) Enabled

func (f *ResourceFeature) Enabled() (bool, error)

Enabled reports whether the feature should apply.

A feature is enabled only if: - all When conditions are true - all version constraints match the current version.

func (*ResourceFeature) When

func (f *ResourceFeature) When(truth bool) *ResourceFeature

When adds a boolean condition that must be true for the feature to be enabled.

Calls are additive: all values passed through When must be true for Enabled() to return true.

type VersionConstraint

type VersionConstraint interface {
	// Enabled reports whether the feature is enabled for the given version string.
	Enabled(version string) (bool, error)
}

VersionConstraint defines a condition based on a semantic version. Implementations should report whether a feature is enabled for the given version string.

Jump to

Keyboard shortcuts

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