mid

package
v0.0.0-...-7e6ed35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mid provides app level middleware support.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidID = errors.New("ID is not in its proper form")

ErrInvalidID represents a condition where the id is not a uuid.

Functions

func Authenticate

func Authenticate(ctx context.Context, log *logger.Logger, client *authclient.Client, authorization string, next Handler) (any, error)

Authenticate validates authentication via the auth service.

func Authorize

func Authorize(ctx context.Context, log *logger.Logger, client *authclient.Client, rule string, next Handler) (any, error)

Authorize validates authorization via the auth service.

func AuthorizeHome

func AuthorizeHome(ctx context.Context, log *logger.Logger, client *authclient.Client, homeBus *homebus.Business, id string, next Handler) (any, error)

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

func AuthorizeProduct(ctx context.Context, log *logger.Logger, client *authclient.Client, productBus *productbus.Business, id string, next Handler) (any, error)

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

func AuthorizeUser(ctx context.Context, log *logger.Logger, client *authclient.Client, userBus *userbus.Business, rule string, id string, next Handler) (any, error)

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 Basic

func Basic(ctx context.Context, ath *auth.Auth, userBus *userbus.Business, authorization string, next Handler) (any, error)

Basic processes basic authentication logic.

func Bearer

func Bearer(ctx context.Context, ath *auth.Auth, authorization string, next Handler) (any, error)

Bearer processes JWT authentication logic.

func BeginCommitRollback

func BeginCommitRollback(ctx context.Context, log *logger.Logger, bgn transaction.Beginner, next Handler) (any, error)

BeginCommitRollback starts a transaction for the domain call.

func Errors

func Errors(ctx context.Context, log *logger.Logger, next Handler) (any, error)

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 GetClaims

func GetClaims(ctx context.Context) auth.Claims

GetClaims returns the claims from the context.

func GetHome

func GetHome(ctx context.Context) (homebus.Home, error)

GetHome returns the home from the context.

func GetProduct

func GetProduct(ctx context.Context) (productbus.Product, error)

GetProduct returns the product from the context.

func GetTran

GetTran retrieves the value that can manage a transaction.

func GetUser

func GetUser(ctx context.Context) (userbus.User, error)

GetUser returns the user from the context.

func GetUserID

func GetUserID(ctx context.Context) (uuid.UUID, error)

GetUserID returns the user id from the context.

func Logger

func Logger(ctx context.Context, log *logger.Logger, path string, rawQuery string, method string, remoteAddr string, next Handler) (any, error)

Logger writes information about the request to the logs.

func Metrics

func Metrics(ctx context.Context, next Handler) (any, error)

Metrics updates program counters.

func Panics

func Panics(ctx context.Context, next Handler) (resp any, err error)

Panics recovers from panics and converts the panic to an error so it is reported in Metrics and handled in Errors.

Types

type Handler

type Handler func(context.Context) (any, error)

Handler represents a handler function that needs to be called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL