Documentation
¶
Overview ¶
Package plan manages SaaS plan metadata, features, and quotas.
Index ¶
- Constants
- Variables
- type Feature
- type ListFilter
- type MemoryService
- func (service *MemoryService) Create(ctx context.Context, plan Plan) error
- func (service *MemoryService) Delete(ctx context.Context, id string) error
- func (service *MemoryService) Get(ctx context.Context, id string) (Plan, error)
- func (service *MemoryService) List(ctx context.Context, filter ListFilter) ([]Plan, error)
- func (service *MemoryService) ListPage(ctx context.Context, filter PageFilter) ([]Plan, error)
- func (service *MemoryService) Update(ctx context.Context, plan Plan) error
- type MemoryStore
- type PageFilter
- type PagedStore
- type Plan
- type Quota
- type QuotaPeriod
- type SQLDialect
- type SQLStore
- func (store *SQLStore) Create(ctx context.Context, plan Plan) error
- func (store *SQLStore) Delete(ctx context.Context, id string) error
- func (store *SQLStore) Get(ctx context.Context, id string) (Plan, error)
- func (store *SQLStore) List(ctx context.Context, filter ListFilter) (plans []Plan, err error)
- func (store *SQLStore) ListPage(ctx context.Context, filter PageFilter) (plans []Plan, err error)
- func (store *SQLStore) Update(ctx context.Context, plan Plan) error
- type SQLStoreOption
- type Service
- type Store
Constants ¶
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 )
const (
// DefaultSQLTableName is the default plan table name.
DefaultSQLTableName = "saas_plans"
)
Variables ¶
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 ListFilter ¶ added in v0.1.6
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) 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.
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 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
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.
type SQLStoreOption ¶ added in v0.1.6
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.