Documentation
¶
Index ¶
- Constants
- Variables
- func IDForKey(key string) uuid.UUID
- func NewEnvironmentRepository(db *bun.DB) repository.Repository[*Environment]
- func NormalizeKey(key string) string
- func ResolveKey(key, defaultKey string, requireExplicit bool) (string, error)
- type BunEnvironmentRepository
- func (r *BunEnvironmentRepository) Create(ctx context.Context, env *Environment) (*Environment, error)
- func (r *BunEnvironmentRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *BunEnvironmentRepository) GetByID(ctx context.Context, id uuid.UUID) (*Environment, error)
- func (r *BunEnvironmentRepository) GetByKey(ctx context.Context, key string) (*Environment, error)
- func (r *BunEnvironmentRepository) GetDefault(ctx context.Context) (*Environment, error)
- func (r *BunEnvironmentRepository) List(ctx context.Context) ([]*Environment, error)
- func (r *BunEnvironmentRepository) ListActive(ctx context.Context) ([]*Environment, error)
- func (r *BunEnvironmentRepository) Update(ctx context.Context, env *Environment) (*Environment, error)
- type CreateEnvironmentInput
- type Environment
- type EnvironmentRepository
- type IDDeriver
- type NotFoundError
- type Service
- type ServiceOption
- type UpdateEnvironmentInput
Constants ¶
const DefaultID = defaultEnvironmentID
DefaultID is the canonical UUID for the default environment key.
const DefaultKey = defaultEnvironmentKey
DefaultKey is the canonical fallback environment key.
Variables ¶
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") )
Functions ¶
func NewEnvironmentRepository ¶
func NewEnvironmentRepository(db *bun.DB) repository.Repository[*Environment]
NewEnvironmentRepository creates a repository for environment records.
func NormalizeKey ¶
NormalizeKey trims and lowercases environment keys.
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 (r *BunEnvironmentRepository) Create(ctx context.Context, env *Environment) (*Environment, error)
func (*BunEnvironmentRepository) GetByID ¶
func (r *BunEnvironmentRepository) GetByID(ctx context.Context, id uuid.UUID) (*Environment, error)
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 (r *BunEnvironmentRepository) List(ctx context.Context) ([]*Environment, error)
func (*BunEnvironmentRepository) ListActive ¶
func (r *BunEnvironmentRepository) ListActive(ctx context.Context) ([]*Environment, error)
func (*BunEnvironmentRepository) Update ¶
func (r *BunEnvironmentRepository) Update(ctx context.Context, env *Environment) (*Environment, error)
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 NotFoundError ¶
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 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).