middleware

package
v0.0.0-...-5863de9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiErrorMiddleWare = func(ctx *fiber.Ctx, err error) error {
	logrus.WithError(err).Errorf("Unexpeceted error")
	if apiError, ok := err.(apierrors.Error); ok {
		return ctx.Status(apiError.StatusCode()).JSON(dto.ErrorResponse{
			Message: apiError.Error(),
		})
	} else {
		return ctx.Status(http.StatusInternalServerError).JSON(dto.ErrorResponse{
			Message: fmt.Sprintf("Unexpected error: %s", err.Error()),
		})
	}
}
View Source
var AuthMiddlewareMiddleWare = func(ctx *fiber.Ctx) error {

	token := ctx.Get(authHeader)
	if token == "" {
		return apierrors.NewApiError("Missing authorization token", http.StatusUnauthorized)
	}
	valid, claim := security.GetClaim(token)
	if !valid {
		return apierrors.NewApiError("Invalid authorization token", http.StatusForbidden)
	}
	ctx.SetUserContext(security.AddClaimToContext(claim, ctx.UserContext()))
	return ctx.Next()
}
View Source
var I18NMiddleware = func(ctx *fiber.Ctx) error {
	localize := i18n.GetLocalize(language.MustParse(ctx.Get(languageHeader, "en")))
	ctx.SetUserContext(context.WithValue(ctx.UserContext(), "i18n", localize))
	return ctx.Next()
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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