Documentation ¶
Overview ¶
Package apis implements the default PocketBase api services and middlewares.
Index ¶
- Constants
- func ActivityLogger(app core.App) echo.MiddlewareFunc
- func BindAdminApi(app core.App, rg *echo.Group)
- func BindCollectionApi(app core.App, rg *echo.Group)
- func BindFileApi(app core.App, rg *echo.Group)
- func BindLogsApi(app core.App, rg *echo.Group)
- func BindRealtimeApi(app core.App, rg *echo.Group)
- func BindRecordApi(app core.App, rg *echo.Group)
- func BindSettingsApi(app core.App, rg *echo.Group)
- func BindUserApi(app core.App, rg *echo.Group)
- func InitApi(app core.App) (*echo.Echo, error)
- func LoadAuthContext(app core.App) echo.MiddlewareFunc
- func LoadCollectionContext(app core.App) echo.MiddlewareFunc
- func RequireAdminAuth() echo.MiddlewareFunc
- func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc
- func RequireAdminOrOwnerAuth(ownerIdParam string) echo.MiddlewareFunc
- func RequireAdminOrUserAuth() echo.MiddlewareFunc
- func RequireGuestOnly() echo.MiddlewareFunc
- func RequireUserAuth() echo.MiddlewareFunc
- func StaticDirectoryHandler(fileSystem fs.FS, disablePathUnescaping bool) echo.HandlerFunc
Constants ¶
const ( ContextUserKey string = "user" ContextAdminKey string = "admin" ContextCollectionKey string = "collection" )
Common request context keys used by the middlewares and api handlers.
Variables ¶
This section is empty.
Functions ¶
func ActivityLogger ¶
ActivityLogger middleware takes care to save the request information into the logs database.
The middleware does nothing if the app logs retention period is zero (aka. app.Settings().Logs.MaxDays = 0).
func BindAdminApi ¶
BindAdminApi registers the admin api endpoints and the corresponding handlers.
func BindCollectionApi ¶
BindCollectionApi registers the collection api endpoints and the corresponding handlers.
func BindFileApi ¶
BindFileApi registers the file api endpoints and the corresponding handlers.
func BindLogsApi ¶
BindLogsApi registers the request logs api endpoints.
func BindRealtimeApi ¶
BindRealtimeApi registers the realtime api endpoints.
func BindRecordApi ¶
BindRecordApi registers the record api endpoints and the corresponding handlers.
func BindSettingsApi ¶
BindSettingsApi registers the settings api endpoints.
func BindUserApi ¶
BindUserApi registers the user api endpoints and the corresponding handlers.
func InitApi ¶
InitApi creates a configured echo instance with registered system and app specific routes and middlewares.
func LoadAuthContext ¶
LoadAuthContext middleware reads the Authorization request header and loads the token related user or admin instance into the request's context.
This middleware is expected to be registered by default for all routes.
func LoadCollectionContext ¶
LoadCollectionContext middleware finds the collection with related path identifier and loads it into the request context.
func RequireAdminAuth ¶
func RequireAdminAuth() echo.MiddlewareFunc
RequireAdminAuth middleware requires a request to have a valid admin Authorization header set (aka. `Authorization: Admin ...`).
func RequireAdminAuthOnlyIfAny ¶
RequireAdminAuthOnlyIfAny middleware requires a request to have a valid admin Authorization header set (aka. `Authorization: Admin ...`) ONLY if the application has at least 1 existing Admin model.
func RequireAdminOrOwnerAuth ¶
func RequireAdminOrOwnerAuth(ownerIdParam string) echo.MiddlewareFunc
RequireAdminOrOwnerAuth middleware requires a request to have a valid admin or user owner Authorization header set (aka. `Authorization: Admin ...` or `Authorization: User ...`).
This middleware is similar to [apis.RequireAdminOrUserAuth()] but for the user token expects to have the same id as the path parameter `ownerIdParam` (default to "id").
func RequireAdminOrUserAuth ¶
func RequireAdminOrUserAuth() echo.MiddlewareFunc
RequireAdminOrUserAuth middleware requires a request to have a valid admin or user Authorization header set (aka. `Authorization: Admin ...` or `Authorization: User ...`).
This middleware is the opposite of [apis.RequireGuestOnly()].
func RequireGuestOnly ¶
func RequireGuestOnly() echo.MiddlewareFunc
RequireGuestOnly middleware requires a request to NOT have a valid Authorization header set.
This middleware is the opposite of [apis.RequireAdminOrUserAuth()].
func RequireUserAuth ¶
func RequireUserAuth() echo.MiddlewareFunc
RequireUserAuth middleware requires a request to have a valid user Authorization header set (aka. `Authorization: User ...`).
func StaticDirectoryHandler ¶
StaticDirectoryHandler is similar to `echo.StaticDirectoryHandler` but without the directory redirect which conflicts with RemoveTrailingSlash middleware.
Types ¶
This section is empty.