plan

package
v0.1.6 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: 9 Imported by: 0

Documentation

Overview

Package plan manages SaaS plan metadata, features, and quotas.

Index

Constants

View Source
const (
	// SQLDialectMySQL uses question-mark placeholders and is the default.
	SQLDialectMySQL = sqlutil.DialectMySQL

	// SQLDialectSQLite uses question-mark placeholders.
	SQLDialectSQLite = sqlutil.DialectSQLite

	// SQLDialectPostgres uses numbered placeholders.
	SQLDialectPostgres = sqlutil.DialectPostgres
)
View Source
const (
	// DefaultSQLTableName is the default plan table name.
	DefaultSQLTableName = "saas_plans"
)

Variables

View Source
var (
	// ErrPlanNotFound reports that a plan does not exist.
	ErrPlanNotFound = errors.New("gotenancy/plan: plan not found")

	// ErrPlanAlreadyExists reports that a plan already exists.
	ErrPlanAlreadyExists = errors.New("gotenancy/plan: plan already exists")

	// ErrInvalidPlan reports invalid plan metadata.
	ErrInvalidPlan = errors.New("gotenancy/plan: invalid plan")

	// ErrInvalidListFilter reports an invalid plan list filter.
	ErrInvalidListFilter = errors.New("gotenancy/plan: invalid list filter")

	// ErrNilDB reports that a SQL store was created with a nil database handle.
	ErrNilDB = errors.New("gotenancy/plan: nil db")

	// ErrInvalidTableName reports an unsafe SQL table name.
	ErrInvalidTableName = errors.New("gotenancy/plan: invalid table name")

	// ErrUnsupportedSQLDialect reports an unsupported SQLStore dialect.
	ErrUnsupportedSQLDialect = errors.New("gotenancy/plan: unsupported sql dialect")
)

Functions

This section is empty.

Types

type Feature

type Feature struct {
	Key     string
	Enabled bool
	Config  map[string]string
}

Feature describes a plan feature flag.

type ListFilter added in v0.1.6

type ListFilter struct {
	IDs    []string
	Limit  int
	Offset int
}

ListFilter restricts plan list queries.

type MemoryService

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

MemoryService is a thread-safe in-memory plan service.

func NewMemoryService

func NewMemoryService() *MemoryService

NewMemoryService creates an empty plan service.

func (*MemoryService) Create

func (service *MemoryService) Create(ctx context.Context, plan Plan) error

Create inserts a plan.

func (*MemoryService) Delete

func (service *MemoryService) Delete(ctx context.Context, id string) error

Delete removes a plan.

func (*MemoryService) Get

func (service *MemoryService) Get(ctx context.Context, id string) (Plan, error)

Get returns a plan by ID.

func (*MemoryService) List added in v0.1.6

func (service *MemoryService) List(ctx context.Context, filter ListFilter) ([]Plan, error)

List returns plans matching filter.

func (*MemoryService) ListPage added in v0.1.6

func (service *MemoryService) ListPage(ctx context.Context, filter PageFilter) ([]Plan, error)

ListPage returns plans after the cursor while preserving List filtering semantics.

func (*MemoryService) Update

func (service *MemoryService) Update(ctx context.Context, plan Plan) error

Update replaces a plan.

type MemoryStore added in v0.1.6

type MemoryStore = MemoryService

MemoryStore is kept as a Store-oriented name for MemoryService.

func NewMemoryStore added in v0.1.6

func NewMemoryStore() *MemoryStore

NewMemoryStore creates an empty plan store.

type PageFilter added in v0.1.6

type PageFilter struct {
	IDs    []string
	Limit  int
	Offset int
	// Cursor returns rows ordered after the plan ID cursor.
	Cursor string
}

PageFilter restricts cursor-based plan list queries.

type PagedStore added in v0.1.6

type PagedStore interface {
	Store
	ListPage(ctx context.Context, filter PageFilter) ([]Plan, error)
}

PagedStore extends Store with cursor-based plan listing.

type Plan

type Plan struct {
	ID       string
	Name     string
	Features []Feature
	Quotas   []Quota
}

Plan describes SaaS package capabilities.

type Quota

type Quota struct {
	Resource string
	Limit    int64
	Period   QuotaPeriod
}

Quota describes a plan resource limit.

type QuotaPeriod

type QuotaPeriod string

QuotaPeriod describes the reset period of a quota.

const (
	QuotaPeriodNone  QuotaPeriod = "none"
	QuotaPeriodDay   QuotaPeriod = "day"
	QuotaPeriodMonth QuotaPeriod = "month"
)

type SQLDialect added in v0.1.6

type SQLDialect = sqlutil.Dialect

SQLDialect controls SQL placeholder rendering for SQLStore.

type SQLStore added in v0.1.6

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

SQLStore persists SaaS plans through database/sql.

The table is expected to contain these columns: id, name, features, quotas. The features and quotas columns store JSON arrays.

func NewSQLStore added in v0.1.6

func NewSQLStore(db *sql.DB, opts ...SQLStoreOption) (*SQLStore, error)

NewSQLStore creates a SQL-backed plan store.

func (*SQLStore) Create added in v0.1.6

func (store *SQLStore) Create(ctx context.Context, plan Plan) error

Create inserts a plan.

func (*SQLStore) Delete added in v0.1.6

func (store *SQLStore) Delete(ctx context.Context, id string) error

Delete removes a plan by ID.

func (*SQLStore) Get added in v0.1.6

func (store *SQLStore) Get(ctx context.Context, id string) (Plan, error)

Get returns a plan by ID.

func (*SQLStore) List added in v0.1.6

func (store *SQLStore) List(ctx context.Context, filter ListFilter) (plans []Plan, err error)

List returns plans matching filter.

func (*SQLStore) ListPage added in v0.1.6

func (store *SQLStore) ListPage(ctx context.Context, filter PageFilter) (plans []Plan, err error)

ListPage returns plans after the cursor while preserving List filtering semantics.

func (*SQLStore) Update added in v0.1.6

func (store *SQLStore) Update(ctx context.Context, plan Plan) error

Update replaces a plan.

type SQLStoreOption added in v0.1.6

type SQLStoreOption func(*SQLStore) error

SQLStoreOption configures SQLStore.

func WithSQLDialect added in v0.1.6

func WithSQLDialect(dialect SQLDialect) SQLStoreOption

WithSQLDialect configures SQL placeholder rendering.

func WithTableName added in v0.1.6

func WithTableName(table string) SQLStoreOption

WithTableName overrides the default plan table name.

type Service

type Service interface {
	Create(ctx context.Context, plan Plan) error
	Get(ctx context.Context, id string) (Plan, error)
	Update(ctx context.Context, plan Plan) error
	Delete(ctx context.Context, id string) error
}

Service manages SaaS plans.

type Store added in v0.1.6

type Store interface {
	Service
	List(ctx context.Context, filter ListFilter) ([]Plan, error)
}

Store persists SaaS plans.

Jump to

Keyboard shortcuts

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