tenant

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Overview

Package tenant manages tenant lifecycle transitions and host-only destructive operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidState reports an invalid tenant lifecycle transition.
	ErrInvalidState = gotenancy.ErrInvalidState

	// ErrHostRequired reports that an operation requires host-side context.
	ErrHostRequired = gotenancy.ErrHostRequired
)

Functions

This section is empty.

Types

type Auditor

type Auditor func(context.Context, Event) error

Auditor records lifecycle events.

type CreateInput

type CreateInput struct {
	ID     types.TenantID
	Name   string
	PlanID string
	Config map[string]string
}

CreateInput describes a tenant to create.

type Event

type Event struct {
	TenantID types.TenantID
	Action   string
	From     types.TenantStatus
	To       types.TenantStatus
}

Event describes a tenant lifecycle event.

type IDGenerator

type IDGenerator func(context.Context) (types.TenantID, error)

IDGenerator creates tenant identifiers when CreateInput omits ID.

type Manager

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

Manager implements tenant lifecycle operations.

func New

func New(store store.Store, opts ...Option) *Manager

New creates a tenant manager.

func (*Manager) Activate

func (manager *Manager) Activate(ctx context.Context, id types.TenantID) (types.Tenant, error)

Activate transitions a Pending tenant to Active.

func (*Manager) Create

func (manager *Manager) Create(ctx context.Context, input CreateInput) (types.Tenant, error)

Create creates a Pending tenant and runs the optional seeder.

func (*Manager) Delete

func (manager *Manager) Delete(ctx context.Context, id types.TenantID) error

Delete soft-deletes tenant metadata.

func (*Manager) Get

func (manager *Manager) Get(ctx context.Context, id types.TenantID) (types.Tenant, error)

Get returns tenant metadata.

func (*Manager) HardDelete

func (manager *Manager) HardDelete(ctx context.Context, id types.TenantID) error

HardDelete physically removes a tenant and requires host context.

func (*Manager) Restore

func (manager *Manager) Restore(ctx context.Context, id types.TenantID) (types.Tenant, error)

Restore transitions a Suspended tenant to Active.

func (*Manager) SoftDelete

func (manager *Manager) SoftDelete(ctx context.Context, id types.TenantID) (types.Tenant, error)

SoftDelete transitions an Active or Suspended tenant to SoftDeleted.

func (*Manager) Suspend

func (manager *Manager) Suspend(ctx context.Context, id types.TenantID) (types.Tenant, error)

Suspend transitions an Active tenant to Suspended.

func (*Manager) Update

func (manager *Manager) Update(ctx context.Context, input UpdateInput) (types.Tenant, error)

Update updates tenant metadata without changing lifecycle status.

type Option

type Option func(*Manager)

Option configures Manager.

func WithAuditor

func WithAuditor(auditor Auditor) Option

WithAuditor sets the lifecycle auditor.

func WithIDGenerator

func WithIDGenerator(generator IDGenerator) Option

WithIDGenerator sets the ID generator.

func WithSeeder

func WithSeeder(seeder Seeder) Option

WithSeeder sets the tenant seeder.

type Seeder

type Seeder func(context.Context, types.Tenant) error

Seeder initializes tenant-scoped data after a tenant is created.

type Service

type Service interface {
	Create(ctx context.Context, input CreateInput) (types.Tenant, error)
	Get(ctx context.Context, id types.TenantID) (types.Tenant, error)
	Update(ctx context.Context, input UpdateInput) (types.Tenant, error)
	Delete(ctx context.Context, id types.TenantID) error
	Activate(ctx context.Context, id types.TenantID) (types.Tenant, error)
	Suspend(ctx context.Context, id types.TenantID) (types.Tenant, error)
	Restore(ctx context.Context, id types.TenantID) (types.Tenant, error)
	SoftDelete(ctx context.Context, id types.TenantID) (types.Tenant, error)
	HardDelete(ctx context.Context, id types.TenantID) error
}

Service manages tenant lifecycle operations.

type UpdateInput

type UpdateInput struct {
	ID     types.TenantID
	Name   string
	PlanID string
	Config map[string]string
}

UpdateInput describes tenant metadata changes.

Jump to

Keyboard shortcuts

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