Documentation
¶
Index ¶
- Constants
- 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 UserFromContext(c echo.Context) (user xuser.User, found bool)
- func UserFromContextOrError(c echo.Context) (user xuser.User, err error)
- type HTTPStatusProvider
- type Module
- type PrivateHandlerFunc
- type Route
- type Validating
Constants ¶
const ImpersonatingUserKeyName = "ImpersonatingUser"
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 ¶
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 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.
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 PrivateHandlerFunc ¶ added in v0.28.0
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
type Validating ¶ added in v0.41.0
type Validating interface {
Validate() error
}
Validating is an interface that can be used to validate a struct.