Documentation
¶
Overview ¶
Package api provides HTTP handlers for the application.
Index ¶
- type Account
- type AccountAPI
- func (api *AccountAPI) Create(w http.ResponseWriter, r *http.Request)
- func (api *AccountAPI) Delete(w http.ResponseWriter, r *http.Request)
- func (api *AccountAPI) Get(w http.ResponseWriter, r *http.Request)
- func (api *AccountAPI) Register(mux *http.ServeMux)
- func (api *AccountAPI) Restore(w http.ResponseWriter, r *http.Request)
- func (api *AccountAPI) UpdatePassword(w http.ResponseWriter, r *http.Request)
- type AccountService
- type AuthAPI
- type AuthService
- type Card
- type CardAPI
- func (api *CardAPI) Create(w http.ResponseWriter, r *http.Request)
- func (api *CardAPI) Delete(w http.ResponseWriter, r *http.Request)
- func (api *CardAPI) Get(w http.ResponseWriter, r *http.Request)
- func (api *CardAPI) List(w http.ResponseWriter, r *http.Request)
- func (api *CardAPI) Register(mux *http.ServeMux)
- type CardService
- type CreateAccountRequest
- type CreateAccountResponse
- type CreateCardRequest
- type CreateCardResponse
- type CreateLoginRequest
- type CreateLoginResponse
- type CreateNoteRequest
- type CreateNoteResponse
- type DeleteAccountResponse
- type DeleteCardResponse
- type DeleteLoginResponse
- type DeleteNoteResponse
- type Error
- type ExportResponse
- type GetAccountResponse
- type GetCardResponse
- type GetLoginResponse
- type GetNoteResponse
- type HealthAPI
- type HealthResponse
- type ListCardsResponse
- type ListLoginsResponse
- type ListNotesResponse
- type Login
- type LoginAPI
- func (api *LoginAPI) Create(w http.ResponseWriter, r *http.Request)
- func (api *LoginAPI) Delete(w http.ResponseWriter, r *http.Request)
- func (api *LoginAPI) Get(w http.ResponseWriter, r *http.Request)
- func (api *LoginAPI) List(w http.ResponseWriter, r *http.Request)
- func (api *LoginAPI) Register(mux *http.ServeMux)
- type LoginRequest
- type LoginResponse
- type LoginService
- type LogoutResponse
- type Note
- type NoteAPI
- func (api *NoteAPI) Create(w http.ResponseWriter, r *http.Request)
- func (api *NoteAPI) Delete(w http.ResponseWriter, r *http.Request)
- func (api *NoteAPI) Get(w http.ResponseWriter, r *http.Request)
- func (api *NoteAPI) List(w http.ResponseWriter, r *http.Request)
- func (api *NoteAPI) Register(mux *http.ServeMux)
- type NoteService
- type ReadyResponse
- type RestoreAccountRequest
- type RestoreAccountResponse
- type ToolAPI
- type ToolService
- type UpdatePasswordRequest
- type UpdatePasswordResponse
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
// The user's display name.
DisplayName string `json:"displayName"`
// The user's email address.
Email string `json:"email"`
}
The Account type represents an individual user account as returned by the API.
type AccountAPI ¶
type AccountAPI struct {
// contains filtered or unexported fields
}
The AccountAPI exposes HTTP endpoints for managing individual user accounts.
func NewAccountAPI ¶
func NewAccountAPI(accounts AccountService) *AccountAPI
NewAccountAPI returns a new instance of the AccountAPI type that manages individual user accounts via the given AccountService implementation.
func (*AccountAPI) Create ¶
func (api *AccountAPI) Create(w http.ResponseWriter, r *http.Request)
Create handles an inbound HTTP request to create a new account. On success, it responds with an http.StatusCreated code and a JSON-encoded CreateAccountResponse.
func (*AccountAPI) Delete ¶
func (api *AccountAPI) Delete(w http.ResponseWriter, r *http.Request)
Delete handles an inbound HTTP request to delete the caller's account. On success, it responds with an http.StatusOK code and a JSON-encoded DeleteAccountResponse.
func (*AccountAPI) Get ¶
func (api *AccountAPI) Get(w http.ResponseWriter, r *http.Request)
Get handles an inbound HTTP request to query the caller's account details. On success, it responds with an http.StatusOK code and a JSON-encoded GetAccountResponse.
func (*AccountAPI) Register ¶
func (api *AccountAPI) Register(mux *http.ServeMux)
Register the HTTP endpoints onto the given http.ServeMux.
func (*AccountAPI) Restore ¶
func (api *AccountAPI) Restore(w http.ResponseWriter, r *http.Request)
Restore handles an inbound HTTP request to change an account's password using its restore key. On success, it responds with an http.StatusOK code and a JSON-encoded RestoreAccountResponse.
func (*AccountAPI) UpdatePassword ¶
func (api *AccountAPI) UpdatePassword(w http.ResponseWriter, r *http.Request)
UpdatePassword handles an inbound HTTP request to change the caller's password. On success, it responds with an http.StatusOK code and a JSON-encoded UpdatePasswordResponse.
type AccountService ¶
type AccountService interface {
// Create should create the given account, returning the restore key to be used should the user enter a
// disaster recovery scenario and need to manually decrypt their data. If an account with the given email
// already exists, service.ErrAccountExists should be returned.
Create(account service.Account) ([]byte, error)
// Get should return the account associated with the given identifier. Returning service.ErrAccountNotFound
// if the account does not exist.
Get(id uuid.UUID) (service.Account, error)
// Delete should delete the account associated with the given identifier. Returning service.ErrAccountNotFound
// if the account does not exist.
Delete(id uuid.UUID) error
// ChangePassword should update the account's password to the new value if the old password provided is
// correct, returning the restore key to be used should the user enter a disaster recovery scenario and need to
// manually decrypt their data.
ChangePassword(id uuid.UUID, oldPassword string, newPassword string) ([]byte, error)
// Restore should update the account associated with the given email address' password after verifying the
// provided restore key is valid. Returning service.ErrAccountNotFound if the account does not exist or
// service.ErrInvalidRestoreKey if the given restore key is invalid. On success, it should return the new
// restore key to be used should the user enter a disaster recovery scenario and need to manually decrypt their
// data.
Restore(email string, restoreKey []byte, newPassword string) ([]byte, error)
}
The AccountService interface describes types that manage individual user accounts.
type AuthAPI ¶
type AuthAPI struct {
// contains filtered or unexported fields
}
The AuthAPI exposes HTTP endpoints for authenticating individual user accounts.
func NewAuthAPI ¶
func NewAuthAPI(auth AuthService) *AuthAPI
NewAuthAPI returns a new instance of the AuthAPI type that manages authenticating user accounts via the given AuthService implementation.
func (*AuthAPI) Login ¶
func (api *AuthAPI) Login(w http.ResponseWriter, r *http.Request)
Login handles an inbound HTTP request to generate a new authentication token for a user. On success, it responds with an http.StatusOK code and a JSON-encoded LoginResponse.
type AuthService ¶
type AuthService interface {
// Login should return a token.Token if the provided email and password combination is correct. This Token should
// be given to the user for subsequent API calls.
Login(email string, password string) (token.Token, error)
// Logout should close any account databases associated with the given UUID.
Logout(id uuid.UUID) error
}
The AuthService interface describes types that manage authentication of users.
type Card ¶
type Card struct {
// The unique identifier of the card.
ID string `json:"id"`
// The cardholder's name.
HolderName string `json:"holderName"`
// The card number.
Number string `json:"number"`
// The month the card expires.
ExpiryMonth time.Month `json:"expiryMonth"`
// The year the card expires.
ExpiryYear int `json:"expiryYear"`
// The card's CVV.
CVV string `json:"cvv"`
// When the card was created.
CreatedAt time.Time `json:"createdAt"`
// A user-supplied name for the card
Name string `json:"name"`
// The card issuer
Issuer string `json:"issuer"`
}
The Card type represents a single payment card.
type CardAPI ¶
type CardAPI struct {
// contains filtered or unexported fields
}
The CardAPI exposes HTTP endpoints for managing individual payment cards.
func NewCardAPI ¶
func NewCardAPI(cards CardService) *CardAPI
NewCardAPI returns a new instance of the CardAPI type that manages payment cards via the given CardService implementation.
func (*CardAPI) Create ¶
func (api *CardAPI) Create(w http.ResponseWriter, r *http.Request)
Create handles an inbound HTTP request to store a new payment card record for a user. On success, it responds with an http.StatusCreated code and a JSON-encoded CreateCardResponse.
func (*CardAPI) Delete ¶
func (api *CardAPI) Delete(w http.ResponseWriter, r *http.Request)
Delete handles an inbound HTTP request to delete a payment card record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded DeleteCardResponse.
func (*CardAPI) Get ¶
func (api *CardAPI) Get(w http.ResponseWriter, r *http.Request)
Get handles an inbound HTTP request to query a payment card record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded GetCardResponse.
type CardService ¶
type CardService interface {
// Create should create a new payment card record for the given user id.
Create(accountID uuid.UUID, card service.Card) error
// List should return all cards associated with the given user id.
List(accountID uuid.UUID, filters ...filter.Filter[service.Card]) ([]service.Card, error)
// Delete should remove the payment card record associated with the given user and card id. Returning
// service.ErrCardNotFound if it does not exist.
Delete(accountID uuid.UUID, cardID uuid.UUID) error
// Get should return the payment card record associated with the given user and card id. Returning
// service.ErrCardNotFound if it does not exist.
Get(accountID uuid.UUID, cardID uuid.UUID) (service.Card, error)
}
The CardService interface describes types that manage payment cards.
type CreateAccountRequest ¶
type CreateAccountRequest struct {
// The user's email address.
Email string `json:"email"`
// The user's password.
Password string `json:"password"`
// The user's display name.
DisplayName string `json:"displayName"`
}
The CreateAccountRequest type represents the request body given when calling AccountAPI.Create.
func (CreateAccountRequest) Validate ¶
func (r CreateAccountRequest) Validate() error
Validate the request.
type CreateAccountResponse ¶
type CreateAccountResponse struct {
// The key to use if manual data decryption is required.
RestoreKey []byte `json:"restoreKey"`
}
The CreateAccountResponse type represents the response body returned when calling AccountAPI.Create.
type CreateCardRequest ¶
type CreateCardRequest struct {
// The cardholder's name.
HolderName string `json:"holderName"`
// The card number.
Number string `json:"number"`
// The month the card expires.
ExpiryMonth time.Month `json:"expiryMonth"`
// The year the card expires.
ExpiryYear int `json:"expiryYear"`
// The card's CVV.
CVV string `json:"cvv"`
// A user-supplied name for the card
Name string `json:"name"`
}
The CreateCardRequest type represents the request body given when calling CardAPI.Create
func (CreateCardRequest) Validate ¶
func (r CreateCardRequest) Validate() error
Validate the request.
type CreateCardResponse ¶
type CreateCardResponse struct {
ID string `json:"id"`
}
The CreateCardResponse type represents the response body returned when calling CardAPI.Create
type CreateLoginRequest ¶
type CreateLoginRequest struct {
// The username.
Username string `json:"username"`
// The password.
Password string `json:"password"`
// The domains where this username/password combination can be used.
Domains []string `json:"domains"`
// A user-supplied name for the login.
Name string `json:"name"`
}
The CreateLoginRequest type represents the request body given when calling LoginAPI.Create
func (CreateLoginRequest) Validate ¶
func (r CreateLoginRequest) Validate() error
Validate the request.
type CreateLoginResponse ¶
type CreateLoginResponse struct {
ID string `json:"id"`
}
The CreateLoginResponse type represents the response body returned when calling LoginAPI.Create
type CreateNoteRequest ¶
type CreateNoteRequest struct {
// The note's name.
Name string `json:"name"`
// The note's contents
Content string `json:"content"`
}
The CreateNoteRequest type represents the request body given when calling NoteAPI.Create
func (CreateNoteRequest) Validate ¶
func (r CreateNoteRequest) Validate() error
Validate the request.
type CreateNoteResponse ¶
type CreateNoteResponse struct {
ID string `json:"id"`
}
The CreateNoteResponse type represents the response body returned when calling NoteAPI.Create
type DeleteAccountResponse ¶
type DeleteAccountResponse struct{}
The DeleteAccountResponse type represents the response body returned when calling AccountAPI.Delete
type DeleteCardResponse ¶
type DeleteCardResponse struct{}
The DeleteCardResponse type represents the response body returned when calling CardAPI.Delete
type DeleteLoginResponse ¶
type DeleteLoginResponse struct{}
The DeleteLoginResponse type represents the response body returned when calling LoginAPI.Delete
type DeleteNoteResponse ¶
type DeleteNoteResponse struct{}
The DeleteNoteResponse type represents the response body returned when calling NoteAPI.Delete
type Error ¶
type Error struct {
// The error message.
Message string `json:"message"`
// The error code, should correspond to the HTTP status code used in the response.
Code int `json:"code"`
}
The Error type represents an error as returned by API endpoints.
type ExportResponse ¶
type ExportResponse struct {
// The user's logins.
Logins []Login `json:"logins"`
// The user's notes.
Notes []Note `json:"notes"`
// The user's payment cards.
Cards []Card `json:"cards"`
}
The ExportResponse type represents the response body returned when calling ToolAPI.Export
type GetAccountResponse ¶
type GetAccountResponse struct {
// The user's account details.
Account Account `json:"account"`
}
The GetAccountResponse type represents the response body returned when calling AccountAPI.Get
type GetCardResponse ¶
type GetCardResponse struct {
// The requested card details.
Card Card `json:"card"`
}
The GetCardResponse type represents the response body returned when calling CardAPI.Get
type GetLoginResponse ¶
type GetLoginResponse struct {
// The requested login details.
Login Login `json:"login"`
}
The GetLoginResponse type represents the response body returned when calling LoginAPI.Get
type GetNoteResponse ¶
type GetNoteResponse struct {
// The requested note details.
Note Note `json:"note"`
}
The GetNoteResponse type represents the response body returned when calling NoteAPI.Get
type HealthAPI ¶
type HealthAPI struct {
// contains filtered or unexported fields
}
The HealthAPI exposes HTTP endpoints for checking the health and readiness of the server.
func NewHealthAPI ¶
func NewHealthAPI() *HealthAPI
NewHealthAPI returns a new instance of the HealthAPI type.
func (*HealthAPI) Health ¶
func (api *HealthAPI) Health(w http.ResponseWriter, r *http.Request)
Health handles an inbound HTTP request to check the health of the server. On success, it responds with an http.StatusOK code and a JSON-encoded HealthResponse.
type HealthResponse ¶
type HealthResponse struct {
// The server version.
Version string `json:"version"`
// How long the server has been active for, is the string representation of a time.Duration.
Uptime string `json:"uptime"`
}
The HealthResponse type represents the response body returned when calling HealthAPI.Health.
type ListCardsResponse ¶
type ListCardsResponse struct {
// The cards stored for the account.
Cards []Card `json:"cards"`
}
The ListCardsResponse type represents the response body returned when calling CardAPI.List
type ListLoginsResponse ¶
type ListLoginsResponse struct {
// The logins stored for the account.
Logins []Login `json:"logins"`
}
The ListLoginsResponse type represents the response body returned when calling LoginAPI.List
type ListNotesResponse ¶
type ListNotesResponse struct {
// The notes stored for the account.
Notes []Note `json:"notes"`
}
The ListNotesResponse type represents the response body returned when calling NoteAPI.List
type Login ¶
type Login struct {
// The unique identifier of the login.
ID string `json:"id"`
// The username.
Username string `json:"username"`
// The password.
Password string `json:"password"`
// The domains this password can be used.
Domains []string `json:"domains"`
// When the login was created.
CreatedAt time.Time `json:"createdAt"`
// A user-supplied name for the login.
Name string `json:"name"`
}
The Login type represents a single username/password combination.
type LoginAPI ¶
type LoginAPI struct {
// contains filtered or unexported fields
}
The LoginAPI exposes HTTP endpoints for managing individual user logins.
func NewLoginAPI ¶
func NewLoginAPI(logins LoginService) *LoginAPI
NewLoginAPI returns a new instance of the LoginAPI type that manages user logins via the given LoginService implementation.
func (*LoginAPI) Create ¶
func (api *LoginAPI) Create(w http.ResponseWriter, r *http.Request)
Create handles an inbound HTTP request to store a new login record for a user. On success, it responds with an http.StatusCreated code and a JSON-encoded CreateLoginResponse.
func (*LoginAPI) Delete ¶
func (api *LoginAPI) Delete(w http.ResponseWriter, r *http.Request)
Delete handles an inbound HTTP request to delete a login record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded DeleteLoginResponse.
func (*LoginAPI) Get ¶
func (api *LoginAPI) Get(w http.ResponseWriter, r *http.Request)
Get handles an inbound HTTP request to query a login record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded GetLoginResponse.
type LoginRequest ¶
type LoginRequest struct {
// The user's email address.
Email string `json:"email"`
// The user's password.
Password string `json:"password"`
}
The LoginRequest type represents the request body given when calling AuthAPI.Login
type LoginResponse ¶
type LoginResponse struct {
// The user's authentication token.
Token string `json:"token"`
}
The LoginResponse type represents the response body returned when calling AuthAPI.Login
type LoginService ¶
type LoginService interface {
// Create should create a new login record for the given user id.
Create(accountID uuid.UUID, login service.Login) error
// List should return all logins associated with the given user id.
List(accountID uuid.UUID, filters ...filter.Filter[service.Login]) ([]service.Login, error)
// Delete should remove the login record associated with the given user and login id. Returning
// service.ErrLoginNotFound if it does not exist.
Delete(accountID uuid.UUID, loginID uuid.UUID) error
// Get should return the login record associated with the given user and login id. Returning
// service.ErrLoginNotFound if it does not exist.
Get(accountID uuid.UUID, loginID uuid.UUID) (service.Login, error)
}
The LoginService interface describes types that manage user logins.
type LogoutResponse ¶
type LogoutResponse struct{}
The LogoutResponse type represents the response body returned when calling AuthAPI.Logout
type Note ¶
type Note struct {
// The unique identifier of the note.
ID string `json:"id"`
// The note's name.
Name string `json:"name"`
// The note's contents
Content string `json:"content"`
// When the note was created.
CreatedAt time.Time `json:"createdAt"`
}
The Note type represents a single password.
type NoteAPI ¶
type NoteAPI struct {
// contains filtered or unexported fields
}
The NoteAPI exposes HTTP endpoints for managing individual user notes.
func NewNoteAPI ¶
func NewNoteAPI(notes NoteService) *NoteAPI
NewNoteAPI returns a new instance of the NoteAPI type that manages user notes via the given NoteService implementation.
func (*NoteAPI) Create ¶
func (api *NoteAPI) Create(w http.ResponseWriter, r *http.Request)
Create handles an inbound HTTP request to store a new note record for a user. On success, it responds with an http.StatusCreated code and a JSON-encoded CreateNoteResponse.
func (*NoteAPI) Delete ¶
func (api *NoteAPI) Delete(w http.ResponseWriter, r *http.Request)
Delete handles an inbound HTTP request to delete a note record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded ListNotesResponse.
func (*NoteAPI) Get ¶
func (api *NoteAPI) Get(w http.ResponseWriter, r *http.Request)
Get handles an inbound HTTP request to query a note record for a user. On success, it responds with an http.StatusOK code and a JSON-encoded GetNoteResponse.
type NoteService ¶
type NoteService interface {
// Create should create a new note record for the given user id.
Create(accountID uuid.UUID, note service.Note) error
// List should return all notes associated with the given user id.
List(accountID uuid.UUID, filters ...filter.Filter[service.Note]) ([]service.Note, error)
// Delete should remove the note record associated with the given user and note id. Returning
// service.ErrNoteNotFound if it does not exist.
Delete(accountID uuid.UUID, noteID uuid.UUID) error
// Get should return the note record associated with the given user and note id. Returning
// service.ErrNoteNotFound if it does not exist.
Get(accountID uuid.UUID, noteID uuid.UUID) (service.Note, error)
}
The NoteService interface describes types that manage user notes.
type ReadyResponse ¶
type ReadyResponse struct{}
The ReadyResponse type represents the response body returned when calling HealthAPI.Ready.
type RestoreAccountRequest ¶
type RestoreAccountRequest struct {
// The account's email address.
Email string `json:"email"`
// The account's restore key.
RestoreKey []byte `json:"restoreKey"`
// The user's new password.
NewPassword string `json:"newPassword"`
}
The RestoreAccountRequest type represents the request body given when calling AccountAPI.Restore.
func (RestoreAccountRequest) Validate ¶
func (r RestoreAccountRequest) Validate() error
Validate the request.
type RestoreAccountResponse ¶
type RestoreAccountResponse struct {
// The account's new restore key.
RestoreKey []byte `json:"restoreKey"`
}
The RestoreAccountResponse type represents the response body returned when calling AccountAPI.Restore
type ToolAPI ¶
type ToolAPI struct {
// contains filtered or unexported fields
}
The ToolAPI exposes HTTP endpoints for common user tools, such as import/export.
func NewToolAPI ¶
func NewToolAPI(tools ToolService) *ToolAPI
NewToolAPI returns a new instance of the ToolAPI type that provider user tools via the given ToolService implementation.
type ToolService ¶
type ToolService interface {
// Export should return all the specified user's data as a service.Export type.
Export(accountID uuid.UUID) (service.Export, error)
}
The ToolService interface describes types that provide user tool implementations.
type UpdatePasswordRequest ¶
type UpdatePasswordRequest struct {
// The user's current password.
OldPassword string `json:"oldPassword"`
// The user's new password.
NewPassword string `json:"newPassword"`
}
The UpdatePasswordRequest type represents the request body given when calling AccountAPI.UpdatePassword.
func (UpdatePasswordRequest) Validate ¶
func (r UpdatePasswordRequest) Validate() error
Validate the request.
type UpdatePasswordResponse ¶
type UpdatePasswordResponse struct {
// The key to use if manual data decryption is required.
RestoreKey []byte `json:"restoreKey"`
}
The UpdatePasswordResponse type represents the response body returned when calling AccountAPI.UpdatePassword
type Validatable ¶
type Validatable interface {
// Validate should check the underlying type's validity and return an error if invalid.
Validate() error
}
The Validatable interface describes types that can be validated.