Documentation
¶
Overview ¶
Package authlite is a deliberately small stand-in for a ubgo library that owns tables, for the cookbook. It shows the library-author side of every extension mechanism: exported tables and columns, a bindings function, queries that accept sqlb.Option, a Composite destination, mandatory predicates that options cannot remove, and hooks that receive the transaction. It renders SQL and executes only through the DBTX it is given, so the cookbook runs without a driver.
Index ¶
- Constants
- Variables
- func NotBanned() sqlb.Predicate
- func UserBindings(dst *User) []sqlb.Binding
- type Auth
- func (a *Auth) AdminUserListQuery(limit, offset int, dst *User, opts ...sqlb.Option) (sqlb.Query, error)
- func (a *Auth) LoadUserQuery(userID string, dst Composite) (sqlb.Query, error)
- func (a *Auth) Select() *sqlb.AnySelect
- func (a *Auth) SignUp(ctx context.Context, tx sqlb.DBTX, id, email string) (*User, error)
- func (a *Auth) UserByEmailQuery(email string, dst *User) (sqlb.Query, error)
- type Composite
- type Hooks
- type IdentifierKind
- type Option
- type SignUpEvent
- type User
Constants ¶
const ( TableNameUser = "auth_user" TableAliasUser = "u" TableNameIdentity = "auth_identity" TableAliasIdent = "i" ColID = "id" ColEmail = "primary_email" ColBannedAt = "banned_at" ColCreatedAt = "created_at" ColIdentUserID = "user_id" ColIdentKind = "kind" ColIdentValue = "value" )
Table and column names. Constants so a rename is one edit and the migration file can reference the same names.
Variables ¶
var ( TableUser = sqlb.Table{Name: TableNameUser, Alias: TableAliasUser} TableIdentity = sqlb.Table{Name: TableNameIdentity, Alias: TableAliasIdent} )
Tables owned by the core. Package-level because a plugin in another module declares its join against them at init time.
var ( UserID = sqlb.Col[string](TableUser, ColID) UserEmail = sqlb.Col[string](TableUser, ColEmail) UserBannedAt = sqlb.Col[*time.Time](TableUser, ColBannedAt) UserCreatedAt = sqlb.Col[time.Time](TableUser, ColCreatedAt) )
Typed columns on auth_user. These, with UserBindings, are the public API. Adding one is a minor version; renaming or removing one is a major version.
var ( IdentityUserID = sqlb.Col[string](TableIdentity, ColIdentUserID) IdentityKind = sqlb.Col[IdentifierKind](TableIdentity, ColIdentKind) IdentityValue = sqlb.Col[string](TableIdentity, ColIdentValue) )
Typed columns on auth_identity.
Functions ¶
func NotBanned ¶
NotBanned is the single definition of the rule. Every listing query includes it and no Option can remove it, because options only add.
func UserBindings ¶
UserBindings binds every core column to dst. A function, not a slice, because each binding holds a pointer into dst.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth is the library handle: dialect, hooks, and the query methods.
func New ¶
New wires the handle. In the real library this is where plugin aliases are checked for collisions and configuration is validated.
func (*Auth) AdminUserListQuery ¶
func (a *Auth) AdminUserListQuery(limit, offset int, dst *User, opts ...sqlb.Option) (sqlb.Query, error)
AdminUserListQuery is the paginated listing, open to the application through opts. NotBanned is written before Apply and survives every option.
func (*Auth) LoadUserQuery ¶
LoadUserQuery returns the core user plus every column the composite adds, in one statement.
type Composite ¶
Composite is a destination whose shape the application declares: the core user plus whatever plugins and application tables it composes.
type Hooks ¶
Hooks are the application's write points inside the library's transaction. Each receives the DBTX the library is writing through, so the application's row and the library's row commit or roll back together.
type IdentifierKind ¶
type IdentifierKind string
IdentifierKind names the kind of an identity row. A named string type so a plugin cannot pass an arbitrary string variable as a kind.
const ( KindEmail IdentifierKind = "email" KindPhone IdentifierKind = "phone" )
The identifier kinds the core knows. A plugin adding a kind adds it here, so the closed set stays in one place.
type SignUpEvent ¶
type SignUpEvent struct {
User *User
}
SignUpEvent is passed to the AfterSignUp hook.