Documentation ¶
Index ¶
- func BindValidated[T Validating](c echo.Context) (T, error)
- func ErrorNormalizerMiddleware() echo.MiddlewareFunc
- func FromApi(ctx echo.Context) context.Context
- func ParseParamID(c echo.Context, name string) (ids.Id, error)
- func RealUserFromContext(c echo.Context) (xuser.User, bool)
- func TenantFromContext(c echo.Context) (string, bool)
- func TenantOrDefault(c echo.Context) string
- func UserFromContext(c echo.Context) (user xuser.User, found bool)
- func UserFromContextOrError(c echo.Context) (user xuser.User, err error)
- type HTTPStatusProvider
- type Module
- type Route
- type Validating
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 ¶
FromApi returns a context.Context that wraps the echo.Context. The stored values in the echo.Context are accessible via the context.Context.
func RealUserFromContext ¶
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 ¶
TenantFromContext returns the current user tenant from the API context.
func TenantOrDefault ¶
func TenantOrDefault(c echo.Context) string
func UserFromContext ¶
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 ¶
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 }
type Validating ¶
type Validating interface {
Validate() error
}
Validating is an interface that can be used to validate a struct.