Documentation ¶
Overview ¶
Package accounts provides a mapping of login methods to logical users.
The accounts package provides the definitions of the service and its boundaries. It sets up the Account type, which represents a mapping of a login method to a user within your application, and the Storer interface, which defines how to implement data storage backends for these Accounts.
This package can be thought of as providing the types and helpers that form the conceptual framework of the subsystem, but with very little functionality provided by itself. Instead, implementations of the interfaces and sub-packages using these types are where most functionality will actually live.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAccountNotFound is returned when an Account was expected but could not be found. ErrAccountNotFound = errors.New("account not found") // ErrAccountAlreadyExists is returned when attempting to create an Account that already exists. ErrAccountAlreadyExists = errors.New("account already exists") // ErrProfileIDAlreadyExists is returned when an account is registered by the ProfileID already exists. ErrProfileIDAlreadyExists = errors.New("profileID already exists") )
Functions ¶
func ByLastUsedDesc ¶
func ByLastUsedDesc(accounts []Account)
ByLastUsedDesc sorts the passed slice of Accounts by their LastUsed property, with the most recent times at the lower indices.
Types ¶
type Account ¶
type Account struct { // ID is a globally-unique identifier for how the user identifies // themselves to your application. It is case-insensitive. ID string // ProfileID is how your application should identify the user. It is an // opaque string that will be automatically generated for you. ProfileID string // Created is the time at which the Account was first registered. Created time.Time // LastUsed is the time at which the Account was last authenticated // with by the user, completing the password challenge or clicking the // link in the email, or however the account is authenticated. LastUsed time.Time // LastSeen is the time at which the Account was last seen acting. This // is different from the time it was last authenticated; when an // authentication token issued for this Account is used, LastSeen // should be updated. When the Account is issued an authentication // token, LastUsed and LastSeen should both be updated. LastSeen time.Time // IsRegistration should be set to true when the Account is the first // Account a user is trying to register. This enables extra validation // logic to ensure that ProfileIDs are unique for logical users, but // that multiple Accounts can be registered to a single logical user. IsRegistration bool }
Account is a representation of a user's identifier. It maps the identifier (email, username, whatever) to a profile ID, allowing users to have multiple identifiers that are all interchangeable.
func Apply ¶
Apply returns a copy of the specified Account with the changes requested by the specified Change applied.
func FillDefaults ¶
FillDefaults sets a reasonable default for any of the properties of the specified Account that both have reasonable defaults and are set to the zero value when FillDefaults is called. It returns a copy of the specified Account with those defaults applied.
type Change ¶
Change represents a requested change to one or more of an Account's mutable properties.
type Dependencies ¶
type Dependencies struct {
Storer Storer
}
Dependencies holds all the information that we want to make available to all our functions, but that are orthogonal enough to not warrant their own place in every function's signature.
type Storer ¶
type Storer interface { Create(ctx context.Context, account Account) error Get(ctx context.Context, id string) (Account, error) Update(ctx context.Context, id string, change Change) error Delete(ctx context.Context, id string) error ListByProfile(ctx context.Context, profileID string) ([]Account, error) }
Storer dictates how Accounts will be persisted and how to interact with those persisted Accounts.
Directories ¶
Path | Synopsis |
---|---|
Package apiv1 provides a JSON API for interacting with accounts.
|
Package apiv1 provides a JSON API for interacting with accounts. |
storers
|
|
memory
Package memory provides an in-memory implementation of the lockbox.dev/accounts.Storer interface.
|
Package memory provides an in-memory implementation of the lockbox.dev/accounts.Storer interface. |
postgres
Package postgres provides an implementation of the lockbox.dev/accounts.Storer interface that stores data in a PostgreSQL database.
|
Package postgres provides an implementation of the lockbox.dev/accounts.Storer interface that stores data in a PostgreSQL database. |
postgres/migrations
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation.
|
Package migrations provides access to the SQL migrations used to set up a PostgreSQL database for the postgres Storer implementation. |