Documentation ¶
Overview ¶
Package v0 contains handlers, middleware and response formats for the v0 API.
Index ¶
- func Authentication(publicKey *rsa.PublicKey) fiber.Handler
- func ContentTypeValidation(c *fiber.Ctx) error
- func ErrorHandling(c *fiber.Ctx) error
- func NewBadRequestError(requestID string, cause error) error
- func NewInternalServerError(requestID string, cause error) error
- func NewNotFoundError(requestID string, resource missingResource) error
- func NewPreconditionFailedError(requestID string, resource string, eTag etag.ETag, cause error) error
- func NewUnauthorizedError(requestID string, cause error) error
- func NewUnprocessableEntityError(requestID string, validationErrs user.ValidationErrors) error
- func NewUnsupportedContentTypeError(requestID string, contentType string, supportedContentTypes []string) error
- func UsersErrorHandling(c *fiber.Ctx) error
- type Claims
- type JSONError
- type JWT
- type JWTConfig
- type JWTProvider
- type UsersHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authentication ¶
Authentication wraps Fiber's JWT middleware, parsing the current user ID from the JWT claims and setting it on the request context.
A request ID is expected to be present on the request context.
func ContentTypeValidation ¶
func ContentTypeValidation(c *fiber.Ctx) error
ContentTypeValidation is middleware that validates the request Content-Type header.
func ErrorHandling ¶
func ErrorHandling(c *fiber.Ctx) error
ErrorHandling is middleware that handles errors returned by the v0 API handlers.
func NewBadRequestError ¶
NewBadRequestError should be used in responses to syntactically invalid requests.
func NewInternalServerError ¶
func NewNotFoundError ¶
NewNotFoundError should be used in responses to requests for resources that don't exist.
func NewUnauthorizedError ¶
func NewUnprocessableEntityError ¶
func NewUnprocessableEntityError(requestID string, validationErrs user.ValidationErrors) error
func UsersErrorHandling ¶
func UsersErrorHandling(c *fiber.Ctx) error
UsersErrorHandling is middleware that handles all users endpoint-related response.
Types ¶
type Claims ¶
type Claims struct {
jwt.RegisteredClaims
}
Claims is an extensible set of JWT claims that includes all RFC 7519 Registered Claims.
type JSONError ¶
type JSONError struct { RequestID string `json:"id"` Status int `json:"status"` Message string `json:"message"` Errors map[string][]string `json:"errors,omitempty"` // contains filtered or unexported fields }
JSONError maps an application error to its JSON representation.
type JWTConfig ¶
type JWTConfig struct { RS256PrivateKey *rsa.PrivateKey TTL time.Duration Issuer string }
JWTConfig is the minimal configuration required by [JWTProvider]s and JWT middleware.
type JWTProvider ¶
type JWTProvider interface { // TokenFor returns a signed JWT for the given subject. // // # Errors // - Internal errors related to signing the token. TokenFor(subject uuid.UUID) (JWT, error) }
JWTProvider is a source of signed JSON Web Tokens.
func NewJWTProvider ¶
func NewJWTProvider(privateKey *rsa.PrivateKey, ttl time.Duration, issuer string) JWTProvider
NewJWTProvider returns the default JWT provider.
type UsersHandler ¶
type UsersHandler struct {
// contains filtered or unexported fields
}
UsersHandler holds dependencies for users endpoints.
func NewUsersHandler ¶
func NewUsersHandler(service user.Service, jwtProvider JWTProvider) *UsersHandler
func (*UsersHandler) GetCurrent ¶
func (h *UsersHandler) GetCurrent(c *fiber.Ctx) error
GetCurrent returns the user corresponding to the ID contained in the request JWT.
func (*UsersHandler) Login ¶
func (h *UsersHandler) Login(c *fiber.Ctx) error
Login authenticates a user and returns the user and token if successful.
func (*UsersHandler) Register ¶
func (h *UsersHandler) Register(c *fiber.Ctx) error
Register creates and returns a new user, along with an auth token.
func (*UsersHandler) UpdateCurrent ¶
func (h *UsersHandler) UpdateCurrent(c *fiber.Ctx) error
UpdateCurrent updates the user corresponding to the ID contained in the request JWT.