mid

package
v0.0.0-...-fc8671e Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 26 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(client authclient.Authenticator) web.MidFunc

Authenticate is a middleware function that integrates with an authentication client to validate user credentials and attach user data to the request context.

func Authorize

func Authorize(client authclient.Authenticator, rule string) web.MidFunc

Authorize validates authorization via the auth service.

func AuthorizeHome

func AuthorizeHome(client authclient.Authenticator, homeBus homebus.ExtBusiness) web.MidFunc

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(client authclient.Authenticator, productBus productbus.ExtBusiness) web.MidFunc

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(client authclient.Authenticator, userBus userbus.ExtBusiness, rule string) web.MidFunc

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(ath *auth.Auth, userBus userbus.ExtBusiness) web.MidFunc

Basic processes basic authentication logic.

func Bearer

func Bearer(ath *auth.Auth) web.MidFunc

Bearer processes JWT authentication logic.

func BeginCommitRollback

func BeginCommitRollback(log *logger.Logger, bgn sqldb.Beginner) web.MidFunc

BeginCommitRollback starts a transaction for the domain call.

func Errors

func Errors(log *logger.Logger) web.MidFunc

Errors handles errors coming out of the call chain.

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 GetSubjectID

func GetSubjectID(ctx context.Context) uuid.UUID

GetSubjectID returns the subject id from the claims.

func GetTran

func GetTran(ctx context.Context) (sqldb.CommitRollbacker, error)

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 HandleAuthentication

func HandleAuthentication(ctx context.Context, ath *auth.Auth, authorizationHeader string) (context.Context, *errs.Error)

func HandleAuthorization

func HandleAuthorization(ctx context.Context, authorizationHeader string, userBus userbus.ExtBusiness, ath *auth.Auth) (context.Context, *errs.Error)

func Logger

func Logger(log *logger.Logger) web.MidFunc

Logger writes information about the request to the logs.

func Metrics

func Metrics() web.MidFunc

Metrics updates program counters.

func Otel

func Otel(tracer trace.Tracer) web.MidFunc

Otel starts the otel tracing and stores the trace id in the context.

func Panics

func Panics() web.MidFunc

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.

Jump to

Keyboard shortcuts

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