Documentation
¶
Overview ¶
Package api wraps Huma with Soro routing, errors, resources, and middleware.
Index ¶
- Constants
- func HTTPError(ctx context.Context, err error) error
- func Register[I, O any](router *Router, operation huma.Operation, ...)
- func RequestID(ctx context.Context) string
- type API
- type Action
- type Config
- type ErrorBody
- type ErrorEnvelope
- type Middleware
- type Option
- type PaginationMeta
- type Registrar
- type Resource
- type ResourceConfig
- type ResourceHook
- type Route
- type Router
- type StatusError
Constants ¶
View Source
const RequestIDHeader = "X-Request-ID"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct {
Title string
Version string
BasePath string
OpenAPIPath string
DocsPath string
SchemasPath string
MaxBodyBytes int64
}
func DefaultConfig ¶
func DefaultConfig() Config
type ErrorEnvelope ¶
type ErrorEnvelope struct {
Error ErrorBody `json:"error"`
}
type Option ¶
type Option func(*settings)
func WithLogger ¶
func WithMiddleware ¶
func WithMiddleware(middleware ...Middleware) Option
func WithRequestIDGenerator ¶
type PaginationMeta ¶
type Resource ¶
type Resource[T, C, U, R any] struct { // contains filtered or unexported fields }
Resource implements the five conventional REST operations for one model.
func NewResource ¶
func NewResource[T, C, U, R any](config ResourceConfig[T, C, U, R]) (*Resource[T, C, U, R], error)
type ResourceConfig ¶
type ResourceConfig[T, C, U, R any] struct { Name string Repository *repository.Repository[T] Serializer serializer.Serializer[T, R] CreateEntity func(context.Context, C) (*T, error) UpdateEntity func(context.Context, *T, U) error Query query.Definition Disabled []Action Authorize ResourceHook[T] Before ResourceHook[T] After ResourceHook[T] Scope func(context.Context, *bun.SelectQuery) *bun.SelectQuery ModifyOperation map[Action]func(*huma.Operation) }
ResourceConfig describes a typed REST resource. CreateEntity and UpdateEntity are deliberately explicit so API input can never be reflectively assigned to a persistence model.
type StatusError ¶
type StatusError struct {
ErrorEnvelope
// contains filtered or unexported fields
}
func (*StatusError) ContentType ¶
func (response *StatusError) ContentType(contentType string) string
func (*StatusError) Error ¶
func (response *StatusError) Error() string
func (*StatusError) GetStatus ¶
func (response *StatusError) GetStatus() int
Click to show internal directories.
Click to hide internal directories.