Documentation
¶
Overview ¶
Package rpc is api's server of the contract novatrail.api.v1, on Connect v2 (R17, R18, R33): the methods of the contract, its codecs, and the interceptors every request goes through — its line of the log, its time limit and the checks of architecture 3.1, which run before any handler. The handlers of the methods join it task by task; until then a method answers unimplemented.
Index ¶
- func AccountGone(ctx context.Context) error
- func Failed(ctx context.Context, err error) error
- func Keep(refusal error) error
- func Kept(err error) (refusal error, ok bool)
- func Learner(ctx context.Context, db store.Querier, profileID string) (string, error)
- func Malformed(field string) error
- func Mount(mux *http.ServeMux, server *connect.Server)
- func NewServer(d Deps, h Handlers) *connect.Server
- func NoteFailure(ctx context.Context, err error)
- func Once[Res proto.Message](ctx context.Context, db store.Beginner, k Key, req Keyed, ...) (Res, error)
- func Refuse(ctx context.Context, code connect.Code, cause v1.Cause, ...) error
- type Caller
- type DB
- type Deps
- type Handlers
- type Key
- type Keyed
- type Rights
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccountGone ¶ added in v0.1.5
AccountGone is the account marked "deleting" or deleted: the checks give it, and so does a handler that finds the account gone after them (R20).
func Failed ¶ added in v0.1.5
Failed is a check or a handler that did not finish — the sign-in service, the database, the rights. The client sees the code alone; the log names the failure by its kind.
func Keep ¶ added in v0.1.15
Keep is a refusal of act that commits what act wrote before it, with no record of the key: the close of an attempt that the check of a request found abandoned, or on a package the image no longer gives (R07, R10). A repeat is checked again, and finds what was written.
func Kept ¶ added in v0.1.15
Kept is the refusal err keeps, when it is one of Keep: for a request with no key, which commits what it wrote and answers the refusal after it.
func Learner ¶ added in v0.1.15
Learner is step 5 of architecture 3.1, for the handlers of the learning requests: the profile's consent is confirmed, or the request is refused "no consent" (R116 spec). It gives the profile's age category, read with the consent in one query, by which a module and a task suit the learner (R07). It runs after the checks, on the profile they let through: one gone meanwhile is "no profile".
func Malformed ¶ added in v0.1.15
Malformed is a request whose form the contract refuses: invalid_argument with no Refusal, naming the field.
func Mount ¶
Mount puts the server's methods on mux, with the contract's codecs: binary protobuf, and JSON for debugging, written with the protobuf names (R18; contracts README, sections 6 and 9). The JSON codec of Connect discards unknown fields already.
func NewServer ¶
NewServer is the server of the contract, with every method registered and every interceptor in its order: the log's line outermost, so that it sees every refusal, then the time limit, then the checks.
func NoteFailure ¶ added in v0.1.8
NoteFailure names, in the request's line of the log, a failure that its answer does not show: a deletion done in the database whose rest the job finishes (R21). The line is an error, with the failure's kind.
func Once ¶ added in v0.1.15
func Once[Res proto.Message](ctx context.Context, db store.Beginner, k Key, req Keyed, act func(tx pgx.Tx, accountID string) (Res, store.KeyTarget, error)) (Res, error)
Once runs act under the request's idempotency key, in one transaction with the record of the key, under the account of the caller (R17, R35). The account's row is held FOR NO KEY UPDATE first, so that a repeat beside its first waits for it and finds its record. A record of this method and this request gives its answer, and act does nothing; of another method or request, CAUSE_KEY_ALREADY_USED; one still going, CAUSE_STILL_GOING. Otherwise act acts, and its target is written with the record: the answer, unless it names the submission a repeat reads instead. A refusal of act rolls everything back and is recorded nowhere, but one of Keep commits what act wrote: either way a repeat is checked again. The fingerprint is made before the transaction, so that the account's row and a connection of the pool are held for no more than the hash that checks a repeat. Any error but a refusal of the key is given back as it came, for the caller to answer.
func Refuse ¶
func Refuse(ctx context.Context, code connect.Code, cause v1.Cause, data ...func(*v1.Refusal)) error
Refuse is a refusal of the contract: an error of Connect with its code and the Refusal of its cause as its detail (R17; R97 spec). data, when given, fills the Refusal's data. The message is the cause's name, which holds nothing of the request. The cause goes to the request's line of the log.
Types ¶
type Caller ¶
type Caller struct {
// UID is the sign-in service's ID of the token's user.
UID string
// AuthTime is when that user signed in.
AuthTime time.Time
// AccountID is the account of the UID; empty only on CreateAccount, for a UID
// with no account yet.
AccountID string
}
Caller is who a request is from, as the checks found it: the handler reads it with CallerFrom.
type Deps ¶
type Deps struct {
// Signin is the sign-in service (R32).
Signin authn.Port
// DB is the pool of the database api (R29).
DB DB
// Rights is api's rights in OpenFGA (R31).
Rights Rights
// Log is the service's log.
Log *slog.Logger
// RequestTimeout is the longest a request may run (R33).
RequestTimeout time.Duration
}
Deps is what the server runs on.
type Handlers ¶
type Handlers struct {
Account apiv1connect.AccountServiceHandler
Attempt apiv1connect.AttemptServiceHandler
Learning apiv1connect.LearningServiceHandler
Module apiv1connect.ModuleServiceHandler
Package apiv1connect.PackageServiceHandler
Progress apiv1connect.ProgressServiceHandler
}
Handlers are the methods of the contract that api serves. A service left unset answers unimplemented; the tests set the one they need.
type Key ¶ added in v0.1.15
type Key struct {
// Method is the procedure of the contract.
Method string
// Slow is a fingerprint by argon2id, of a request that carries a PIN or an
// age; SHA-256 otherwise (R35).
Slow bool
// Repeat is the answer of a repeat whose record names a submission, not the
// answer itself: it reads the submission in the repeat's transaction. Nil
// for a method whose records hold their answers.
Repeat func(ctx context.Context, tx pgx.Tx, record store.KeyRecord) (proto.Message, error)
}
Key is how a method records its requests under their keys.