Documentation ¶
Index ¶
- Variables
- func CountHeaderMiddleware(countFetcher ListCountFunc, errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
- func FileUploadMiddleware(partHandlerFunc FileHandleFunc, errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
- func ListCacheMiddleware(hashFetcher ListHashFunc, errorHandler turtleware.ErrorHandlerFunc) func(h http.Handler) http.Handler
- func ListSQLHandler[T any](keySet jwk.Set, listEndpoint GetSQLListEndpoint[T]) http.Handler
- func ListSQLxHandler[T any](keySet jwk.Set, listEndpoint GetSQLxListEndpoint[T]) http.Handler
- func ResourceCacheMiddleware(lastModFetcher ResourceLastModFunc, errorHandler turtleware.ErrorHandlerFunc) func(h http.Handler) http.Handler
- func ResourceCreateHandler[T turtleware.CreateDTO](keySet jwk.Set, createEndpoint CreateEndpoint[T], nextHandler http.Handler) http.Handler
- func ResourceCreateMiddleware[T turtleware.CreateDTO](createFunc CreateFunc[T], errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
- func ResourceDataHandler[T any](dataFetcher ResourceDataFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
- func ResourceHandler[T any](keySet jwk.Set, getEndpoint GetEndpoint[T]) http.Handler
- func ResourcePatchHandler[T turtleware.PatchDTO](keySet jwk.Set, patchEndpoint PatchEndpoint[T], nextHandler http.Handler) http.Handler
- func ResourcePatchMiddleware[T turtleware.PatchDTO](patchFunc PatchFunc[T], errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
- func SQLListDataHandler[T any](dataFetcher ListSQLDataFunc, dataTransformer turtleware.SQLResourceFunc[T], ...) http.Handler
- func SQLxListDataHandler[T any](dataFetcher ListSQLxDataFunc, dataTransformer turtleware.SQLxResourceFunc[T], ...) http.Handler
- func StaticListDataHandler[T any](dataFetcher ListStaticDataFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
- func StaticListHandler[T any](keySet jwk.Set, listEndpoint GetStaticListEndpoint[T]) http.Handler
- func UUIDFromRequestContext(ctx context.Context) (string, error)
- func UUIDMiddleware() func(http.Handler) http.Handler
- type CreateEndpoint
- type CreateFunc
- type FileHandleFunc
- type GetEndpoint
- type GetSQLListEndpoint
- type GetSQLxListEndpoint
- type GetStaticListEndpoint
- type ListCountFunc
- type ListHashFunc
- type ListSQLDataFunc
- type ListSQLxDataFunc
- type ListStaticDataFunc
- type PatchEndpoint
- type PatchFunc
- type ResourceDataFunc
- type ResourceLastModFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContextMissingTenantUUID is an internal error indicating a missing // tenant UUID in the request context, whereas one was expected. ErrContextMissingTenantUUID = errors.New("missing tenant UUID in context") // ErrTokenMissingTenantUUID indicates that a requested was // missing the tenant uuid. ErrTokenMissingTenantUUID = errors.New("token does not include tenant uuid") )
Functions ¶
func CountHeaderMiddleware ¶
func CountHeaderMiddleware( countFetcher ListCountFunc, errorHandler turtleware.ErrorHandlerFunc, ) func(http.Handler) http.Handler
CountHeaderMiddleware is a middleware for injecting an X-Total-Count header into the response, by the provided ListCountFunc. If an error is encountered, the provided ErrorHandlerFunc is called.
func FileUploadMiddleware ¶
func FileUploadMiddleware(partHandlerFunc FileHandleFunc, errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
func ListCacheMiddleware ¶
func ListCacheMiddleware( hashFetcher ListHashFunc, errorHandler turtleware.ErrorHandlerFunc, ) func(h http.Handler) http.Handler
ListCacheMiddleware is a middleware for transparently handling caching via the provided ListHashFunc. The next handler of the middleware is only called on a cache miss. That is, if the If-None-Match header and the fetched hash differ. If the ListHashFunc returns either sql.ErrNoRows or os.ErrNotExist, the sha256 hash of an empty string is assumed as the hash. If an error is encountered, the provided ErrorHandlerFunc is called.
func ListSQLHandler ¶
func ListSQLxHandler ¶
func ResourceCacheMiddleware ¶
func ResourceCacheMiddleware( lastModFetcher ResourceLastModFunc, errorHandler turtleware.ErrorHandlerFunc, ) func(h http.Handler) http.Handler
ResourceCacheMiddleware is a middleware for transparently handling caching of a single entity (or resource) of a tenant via the provided ResourceLastModFunc. The next handler of the middleware is only called when the If-Modified-Since header and the fetched last modification date differ. If an error is encountered, the provided ErrorHandlerFunc is called.
func ResourceCreateHandler ¶
func ResourceCreateHandler[T turtleware.CreateDTO]( keySet jwk.Set, createEndpoint CreateEndpoint[T], nextHandler http.Handler, ) http.Handler
func ResourceCreateMiddleware ¶
func ResourceCreateMiddleware[T turtleware.CreateDTO](createFunc CreateFunc[T], errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
func ResourceDataHandler ¶
func ResourceDataHandler[T any](dataFetcher ResourceDataFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
func ResourceHandler ¶
func ResourcePatchHandler ¶
func ResourcePatchHandler[T turtleware.PatchDTO]( keySet jwk.Set, patchEndpoint PatchEndpoint[T], nextHandler http.Handler, ) http.Handler
func ResourcePatchMiddleware ¶
func ResourcePatchMiddleware[T turtleware.PatchDTO](patchFunc PatchFunc[T], errorHandler turtleware.ErrorHandlerFunc) func(http.Handler) http.Handler
func SQLListDataHandler ¶
func SQLListDataHandler[T any](dataFetcher ListSQLDataFunc, dataTransformer turtleware.SQLResourceFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
func SQLxListDataHandler ¶
func SQLxListDataHandler[T any](dataFetcher ListSQLxDataFunc, dataTransformer turtleware.SQLxResourceFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
func StaticListDataHandler ¶
func StaticListDataHandler[T any](dataFetcher ListStaticDataFunc[T], errorHandler turtleware.ErrorHandlerFunc) http.Handler
func StaticListHandler ¶
Types ¶
type CreateEndpoint ¶
type CreateFunc ¶
type FileHandleFunc ¶
type GetEndpoint ¶
type GetEndpoint[T any] interface { EntityUUID(r *http.Request) (string, error) LastModification(ctx context.Context, tenantUUID string, entityUUID string) (time.Time, error) FetchEntity(ctx context.Context, tenantUUID string, entityUUID string) (T, error) HandleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) }
type GetSQLListEndpoint ¶
type GetSQLListEndpoint[T any] interface { ListHash(ctx context.Context, tenantUUID string, paging turtleware.Paging) (string, error) TotalCount(ctx context.Context, tenantUUID string) (uint, error) FetchRows(ctx context.Context, tenantUUID string, paging turtleware.Paging) (*sql.Rows, error) TransformEntity(ctx context.Context, r *sql.Rows) (T, error) HandleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) }
type GetSQLxListEndpoint ¶
type GetSQLxListEndpoint[T any] interface { ListHash(ctx context.Context, tenantUUID string, paging turtleware.Paging) (string, error) TotalCount(ctx context.Context, tenantUUID string) (uint, error) FetchRows(ctx context.Context, tenantUUID string, paging turtleware.Paging) (*sqlx.Rows, error) TransformEntity(ctx context.Context, r *sqlx.Rows) (T, error) HandleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) }
type GetStaticListEndpoint ¶
type GetStaticListEndpoint[T any] interface { ListHash(ctx context.Context, tenantUUID string, paging turtleware.Paging) (string, error) TotalCount(ctx context.Context, tenantUUID string) (uint, error) FetchEntities(ctx context.Context, tenantUUID string, paging turtleware.Paging) ([]T, error) HandleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) }
type ListCountFunc ¶
ListCountFunc is a function for returning the total amount of entities of a given tenant for a list endpoint. The function may return sql.ErrNoRows or os.ErrNotExist to indicate that there are not elements, for easier handling.
type ListHashFunc ¶
type ListHashFunc func(ctx context.Context, tenantUUID string, paging turtleware.Paging) (string, error)
ListHashFunc is a function for returning a calculated hash for a given subset of entities of a given tenant, via the given paging, for a list endpoint. The function may return sql.ErrNoRows or os.ErrNotExist to indicate that there are not elements, for easier handling.
type ListSQLDataFunc ¶
type ListSQLxDataFunc ¶
type ListStaticDataFunc ¶
type PatchEndpoint ¶
type PatchEndpoint[T turtleware.PatchDTO] interface { EntityUUID(r *http.Request) (string, error) UpdateEntity(ctx context.Context, tenantUUID, entityUUID, userUUID string, patch T, ifUnmodifiedSince time.Time) error HandleError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) }
type ResourceDataFunc ¶
type ResourceLastModFunc ¶
type ResourceLastModFunc func(ctx context.Context, tenantUUID string, entityUUID string) (time.Time, error)
ResourceLastModFunc is a function for returning the last modification data for a specific entity of a given tenant. The function may return sql.ErrNoRows or os.ErrNotExist to indicate that there are not elements, for easier handling.