Documentation ¶
Overview ¶
Package mid contains the set of middleware functions.
Index ¶
- Variables
- func Authenticate(a *auth.Auth) web.MidHandler
- func Authorize(a *auth.Auth, rule string) web.MidHandler
- func AuthorizeHome(a *auth.Auth, hmeCore *home.Core) web.MidHandler
- func AuthorizeProduct(a *auth.Auth, prdCore *product.Core) web.MidHandler
- func AuthorizeUser(a *auth.Auth, usrCore *user.Core) web.MidHandler
- func Cors(origins []string) web.MidHandler
- func Errors(log *logger.Logger) web.MidHandler
- func ExecuteInTransaction(log *logger.Logger, bgn transaction.Beginner) web.MidHandler
- func GetHome(ctx context.Context) (home.Home, error)
- func GetProduct(ctx context.Context) (product.Product, error)
- func GetUser(ctx context.Context) (user.User, error)
- func GetUserID(ctx context.Context) (uuid.UUID, error)
- func Logger(log *logger.Logger) web.MidHandler
- func Metrics() web.MidHandler
- func Panics() web.MidHandler
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidID = errors.New("ID is not in its proper form")
)
Set of error variables for handling auth errors.
Functions ¶
func Authenticate ¶
func Authenticate(a *auth.Auth) web.MidHandler
Authenticate validates a JWT from the `Authorization` header.
func Authorize ¶
func Authorize(a *auth.Auth, rule string) web.MidHandler
Authorize executes the specified role and does not extract any domain data.
func AuthorizeHome ¶
AuthorizeHome executes the specified role and extracts the specified home from the DB if a home id is specified in the call. Depending on the rule specified, the userid from the claims may be compared with the specified user id from the home.
func AuthorizeProduct ¶
AuthorizeProduct executes the specified role and extracts the specified product from the DB if a product id is specified in the call. Depending on the rule specified, the userid from the claims may be compared with the specified user id from the product.
func AuthorizeUser ¶
AuthorizeUser executes the specified role and extracts the specified user from the DB if a user id is specified in the call. Depending on the rule specified, the userid from the claims may be compared with the specified user id.
func Cors ¶
func Cors(origins []string) web.MidHandler
Cors sets the response headers needed for Cross-Origin Resource Sharing
func Errors ¶
func Errors(log *logger.Logger) web.MidHandler
Errors handles errors coming out of the call chain. It detects normal application errors which are used to respond to the client in a uniform way. Unexpected errors (status >= 500) are logged.
func ExecuteInTransaction ¶
func ExecuteInTransaction(log *logger.Logger, bgn transaction.Beginner) web.MidHandler
ExecuteInTransaction starts a transaction around all the storage calls within the scope of the handler function.
func GetProduct ¶
GetProduct returns the product from the context.
func Logger ¶
func Logger(log *logger.Logger) web.MidHandler
Logger writes information about the request to the logs.
func Panics ¶
func Panics() web.MidHandler
Panics recovers from panics and converts the panic to an error so it is reported in Metrics and handled in Errors.
Types ¶
This section is empty.