plan

package
v0.3.2 Latest Latest
Warning

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

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

Documentation

Overview

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

包 plan 管理 SaaS 套餐元数据、功能和配额。

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("saas/plan: plan not found")

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

	// ErrPlanConflict reports that a concurrent writer replaced a plan during update.
	ErrPlanConflict = errors.New("saas/plan: plan update conflict")

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

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

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

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

	// ErrUnsupportedSQLDialect reports an unsupported SQLStore dialect.
	ErrUnsupportedSQLDialect = errors.New("saas/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

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

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

List returns plans matching filter.

func (*MemoryService) ListPage

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

type MemoryStore = MemoryService

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates an empty plan store.

type PageFilter

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

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

type SQLDialect = sqlutil.Dialect

SQLDialect controls SQL placeholder rendering for SQLStore.

type SQLStore

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

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

NewSQLStore creates a SQL-backed plan store.

func (*SQLStore) Create

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

Create inserts a plan.

func (*SQLStore) Delete

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

Delete removes a plan by ID.

func (*SQLStore) Get

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

Get returns a plan by ID.

func (*SQLStore) List

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

List returns plans matching filter.

func (*SQLStore) ListPage

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

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

Update replaces a plan.

type SQLStoreOption

type SQLStoreOption func(*SQLStore) error

SQLStoreOption configures SQLStore.

func WithSQLDialect

func WithSQLDialect(dialect SQLDialect) SQLStoreOption

WithSQLDialect configures SQL placeholder rendering.

func WithTableName

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

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