environments

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultID = defaultEnvironmentID

DefaultID is the canonical UUID for the default environment key.

View Source
const DefaultKey = defaultEnvironmentKey

DefaultKey is the canonical fallback environment key.

Variables

View Source
var (
	ErrEnvironmentRepositoryRequired = errors.New("environments: repository required")
	ErrEnvironmentKeyRequired        = errors.New("environments: key is required")
	ErrEnvironmentKeyInvalid         = errors.New("environments: key is invalid")
	ErrEnvironmentKeyExists          = errors.New("environments: key already exists")
	ErrEnvironmentNameRequired       = errors.New("environments: name is required")
	ErrEnvironmentNotFound           = errors.New("environments: environment not found")
	ErrEnvironmentDefaultProtected   = errors.New("environments: default environment cannot be unset or deleted")
)

Functions

func IDForKey

func IDForKey(key string) uuid.UUID

IDForKey derives deterministic UUIDs for environment keys.

func NewEnvironmentRepository

func NewEnvironmentRepository(db *bun.DB) repository.Repository[*Environment]

NewEnvironmentRepository creates a repository for environment records.

func NormalizeKey

func NormalizeKey(key string) string

NormalizeKey trims and lowercases environment keys.

func ResolveKey

func ResolveKey(key, defaultKey string, requireExplicit bool) (string, error)

ResolveKey normalizes an environment key and applies defaults or explicit requirements.

Types

type BunEnvironmentRepository

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

BunEnvironmentRepository implements EnvironmentRepository with optional caching.

func NewBunEnvironmentRepository

func NewBunEnvironmentRepository(db *bun.DB) *BunEnvironmentRepository

NewBunEnvironmentRepository creates an environment repository without caching.

func NewBunEnvironmentRepositoryWithCache

func NewBunEnvironmentRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, serializer cache.KeySerializer) *BunEnvironmentRepository

NewBunEnvironmentRepositoryWithCache creates an environment repository with caching support.

func (*BunEnvironmentRepository) Create

func (*BunEnvironmentRepository) Delete

func (*BunEnvironmentRepository) GetByID

func (*BunEnvironmentRepository) GetByKey

func (r *BunEnvironmentRepository) GetByKey(ctx context.Context, key string) (*Environment, error)

func (*BunEnvironmentRepository) GetDefault

func (r *BunEnvironmentRepository) GetDefault(ctx context.Context) (*Environment, error)

func (*BunEnvironmentRepository) List

func (*BunEnvironmentRepository) ListActive

func (r *BunEnvironmentRepository) ListActive(ctx context.Context) ([]*Environment, error)

func (*BunEnvironmentRepository) Update

type CreateEnvironmentInput

type CreateEnvironmentInput struct {
	Key         string
	Name        string
	Description *string
	IsActive    *bool
	IsDefault   bool
}

CreateEnvironmentInput captures the information required to register an environment.

type Environment

type Environment = cmsenv.Environment

type EnvironmentRepository

type EnvironmentRepository interface {
	Create(ctx context.Context, env *Environment) (*Environment, error)
	Update(ctx context.Context, env *Environment) (*Environment, error)
	GetByID(ctx context.Context, id uuid.UUID) (*Environment, error)
	GetByKey(ctx context.Context, key string) (*Environment, error)
	List(ctx context.Context) ([]*Environment, error)
	ListActive(ctx context.Context) ([]*Environment, error)
	GetDefault(ctx context.Context) (*Environment, error)
	Delete(ctx context.Context, id uuid.UUID) error
}

EnvironmentRepository exposes persistence operations for environments.

func NewMemoryRepository

func NewMemoryRepository() EnvironmentRepository

NewMemoryRepository constructs an in-memory environment repository.

type IDDeriver

type IDDeriver func(key string) uuid.UUID

IDDeriver produces deterministic environment IDs from keys.

type NotFoundError

type NotFoundError struct {
	Resource string
	Key      string
}

NotFoundError is returned when an environment cannot be located.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Service

type Service interface {
	CreateEnvironment(ctx context.Context, input CreateEnvironmentInput) (*Environment, error)
	UpdateEnvironment(ctx context.Context, input UpdateEnvironmentInput) (*Environment, error)
	DeleteEnvironment(ctx context.Context, id uuid.UUID) error
	GetEnvironment(ctx context.Context, id uuid.UUID) (*Environment, error)
	GetEnvironmentByKey(ctx context.Context, key string) (*Environment, error)
	ListEnvironments(ctx context.Context) ([]*Environment, error)
	ListActiveEnvironments(ctx context.Context) ([]*Environment, error)
	GetDefaultEnvironment(ctx context.Context) (*Environment, error)
}

Service describes environment management capabilities.

func NewService

func NewService(repo EnvironmentRepository, opts ...ServiceOption) Service

NewService constructs an environment service instance.

type ServiceOption

type ServiceOption func(*service)

ServiceOption configures service behaviour.

func WithDefaultEnforcement added in v0.25.0

func WithDefaultEnforcement(enabled bool) ServiceOption

WithDefaultEnforcement toggles protection for the default environment.

func WithIDDeriver

func WithIDDeriver(deriver IDDeriver) ServiceOption

WithIDDeriver overrides environment ID derivation.

func WithNow

func WithNow(now func() time.Time) ServiceOption

WithNow overrides the time source (primarily for tests).

type UpdateEnvironmentInput

type UpdateEnvironmentInput struct {
	ID          uuid.UUID
	Name        *string
	Description *string
	IsActive    *bool
	IsDefault   *bool
}

UpdateEnvironmentInput captures mutable environment fields.

Jump to

Keyboard shortcuts

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