xapi

package
v0.48.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const ImpersonatingUserKeyName = "ImpersonatingUser"
View Source
const UserCtxKey = "x-user"

Variables

This section is empty.

Functions

func BindValidated added in v0.41.0

func BindValidated[T Validating](c echo.Context) (T, error)

BindValidated binds the request (body/param/query) to the given struct and validates it. If the struct is invalid, it returns an error.

func ErrorNormalizerMiddleware added in v0.27.0

func ErrorNormalizerMiddleware() echo.MiddlewareFunc

ErrorNormalizerMiddleware is a middleware that convert general errors to HTTPError. This middleware should be after the logger middleware. The conversion should be performed by the CustomErrorHandler but the logger middleware will not log the real status code if it is not a HTTPError.

func FromApi

func FromApi(ctx echo.Context) context.Context

FromApi returns a context.Context that wraps the echo.Context. The stored values in the echo.Context are accessible via the context.Context.

func ParseParamID added in v0.28.1

func ParseParamID(c echo.Context, name string) (ids.ID, error)

func RealUserFromContext

func RealUserFromContext(c echo.Context) (xuser.User, bool)

RealUserFromContext returns the real authenticated user. If user was impersonated, it returns the impersonating user. If not, the same user in context is returned.

func UserFromContext

func UserFromContext(c echo.Context) (user xuser.User, found bool)

UserFromContext returns the authenticated user from the context. If the user does not exist, or it is an invalid struct, found will be false.

func UserFromContextOrError

func UserFromContextOrError(c echo.Context) (user xuser.User, err error)

UserFromContextOrError returns the authenticated user from the context. If the user does not exist, or it is an invalid struct, returns an error.

Types

type HTTPStatusProvider added in v0.27.0

type HTTPStatusProvider interface {
	HTTPStatus() int
}

type Module added in v0.28.0

type Module interface {
	Routes() []Route
}

Module is an interface that should be implemented by all modules provides API endpoints (Route).

type Route added in v0.28.0

type Route struct {
	Method      string   // HTTP method
	Path        string   // path to the route with path parameters
	Permissions []string // user should have ALL of these permissions to access the route
	Hidden      bool     // if true, the route will not be listed in the documentation nor logs
	IsPublic    bool     // if true, the route will be accessible without authentication
	Handler     echo.HandlerFunc
}

func Hidden added in v0.28.0

func Hidden(method string, path string, handler echo.HandlerFunc) Route

Hidden creates a route that does not require authentication and is hidden from the documentation, logs, and metrics

func Public added in v0.28.0

func Public(method string, path string, handler echo.HandlerFunc) Route

Public creates a route that does not require authentication

type Validating added in v0.41.0

type Validating interface {
	Validate() error
}

Validating is an interface that can be used to validate a struct.

Jump to

Keyboard shortcuts

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