xapi

package
v2.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindValidated

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

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

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 TenantFromContext

func TenantFromContext(c echo.Context) (string, bool)

TenantFromContext returns the current user tenant from the API context.

func TenantOrDefault

func TenantOrDefault(c echo.Context) string

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

type HTTPStatusProvider interface {
	HTTPStatus() int
}

type Module

type Module interface {
	Routes() []Route
}

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

type Route

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

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

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

Public creates a route that does not require authentication

type Validating

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