Documentation
¶
Overview ¶
Package guard enforces tenant-scoped uniqueness rules, such as "one user per e-mail address". A claim is keyed by (tenant, rule, value) and runs in the transaction open in the context, so it commits or rolls back together with the rest of the unit of work.
PgStore needs the guards table from docs/postgres/schema.sql. InMemoryStore follows postgres.InMemoryUnitOfWork rollbacks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTaken is returned when the key is already claimed for the Tenant. // The surrounding transaction stays usable. ErrTaken = errors.New("guard: key already claimed") // ErrNoTenant is returned when the context carries no Tenant. ErrNoTenant = errors.New("guard: no tenant in context") // ErrEmptyKey is returned when the rule or value of a Key is empty. ErrEmptyKey = errors.New("guard: empty rule or value") )
Functions ¶
This section is empty.
Types ¶
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore claims keys in memory. Claims are visible at once and released when the surrounding postgres.InMemoryUnitOfWork rolls back.
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
NewInMemoryStore creates an empty InMemoryStore.
type PgOption ¶
type PgOption func(*PgStore)
PgOption configures a PgStore.
func WithSchema ¶
WithSchema sets the Postgres schema holding the guards table. Defaults to public.
type PgStore ¶
type PgStore struct {
// contains filtered or unexported fields
}
PgStore claims keys in the guards table.
func NewPgStore ¶
NewPgStore creates a PgStore that runs on the transaction in the context, or on pool outside one.