api

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 16 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAnnotations = []fx.Annotation{
	fx.As(new(Handler)),
	fx.ResultTags(`group:"api-handler"`),
}
View Source
var MultipartMaxMemory int64 = 8 * 1024

MultipartMaxMemory is the maximum memory to use when parsing multipart form data.

Functions

func AsHandler added in v0.0.5

func AsHandler(f any, anns ...fx.Annotation) any

func AsMiddleware added in v0.0.5

func AsMiddleware(middleware any) any

func AsMiddlewareFunc added in v0.0.5

func AsMiddlewareFunc(name string, middleware func(huma.API) func(ctx huma.Context, next func(huma.Context))) any

func NewAdapter added in v0.0.5

func NewAdapter(r *echo.Echo, g *echo.Group) huma.Adapter

func Operation

func Operation(base ...Option) func(...Option) huma.Operation

func Register

func Register[I, O any](api huma.API, handler func(context.Context, *I) (*O, error), operation huma.Operation)

func Transform

func Transform[I, O any](errorTransform ErrorTransformerFunc, handler func(context.Context, *I) (*O, error)) func(context.Context, *I) (*O, error)

func WithCreated

func WithCreated(op *huma.Operation)

func WithDelete

func WithDelete(op *huma.Operation)

func WithGet

func WithGet(op *huma.Operation)

func WithNoContent

func WithNoContent(op *huma.Operation)

func WithOK

func WithOK(op *huma.Operation)

func WithPatch

func WithPatch(op *huma.Operation)

func WithPost

func WithPost(op *huma.Operation)

func WithPut

func WithPut(op *huma.Operation)

Types

type Authorizer added in v0.0.5

type Authorizer func(huma.Context) error

type CRUD

type CRUD[
	CB interface {
		Decode(context.Context, *M) error
	},
	UB interface {
		Decode(context.Context, *M) error
	},
	M any,
	ID any,
] struct {
	Info CRUDInfo
	List[M]
	Read[M, ID]
	Create[CB, M, ID]
	Update[UB, M, ID]
	Delete[ID]
	DeleteMany[ID]
}

func (CRUD[CB, UB, M, ID]) Area

func (h CRUD[CB, UB, M, ID]) Area() string

func (CRUD[CB, UB, M, ID]) Register

func (h CRUD[CB, UB, M, ID]) Register(e *echo.Echo, api huma.API)

func (CRUD[CB, UB, M, ID]) Version

func (h CRUD[CB, UB, M, ID]) Version() string

type CRUDInfo

type CRUDInfo struct {
	Area    string
	Version string
}

type Create

type Create[B interface {
	Decode(context.Context, *M) error
}, M any, ID any] struct {
	Saver            func(context.Context, *M) error
	Location         func(string, M) *CreateResponse
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewCreate

func NewCreate[B interface {
	Decode(context.Context, *M) error
}, M any, ID any](
	saver func(context.Context, *M) error,
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) Create[B, M, ID]

func (Create[B, M, ID]) Handler

func (h Create[B, M, ID]) Handler(ctx context.Context, in *CreateInput[B]) (*CreateResponse, error)

func (Create[B, M, ID]) Register

func (h Create[B, M, ID]) Register(_ *echo.Echo, api huma.API)

type CreateInput

type CreateInput[B any] struct {
	Body B
}

type CreateResponse

type CreateResponse struct {
	Location string `header:"Content-Location"`
}

func Location

func Location[ID any](path string, m any) *CreateResponse

type Delete

type Delete[ID any] struct {
	Deleter          func(context.Context, ...ID) error
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewDelete

func NewDelete[ID any](
	deleter func(context.Context, ...ID) error,
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) Delete[ID]

func (Delete[ID]) Handler

func (h Delete[ID]) Handler(ctx context.Context, in *IDInput[ID]) (*struct{}, error)

func (Delete[ID]) Register

func (h Delete[ID]) Register(_ *echo.Echo, api huma.API)

type DeleteMany

type DeleteMany[ID any] struct {
	Deleter          func(context.Context, ...ID) error
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewDeleteMany

func NewDeleteMany[ID any](
	deleter func(context.Context, ...ID) error,
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) DeleteMany[ID]

func (DeleteMany[ID]) Handler

func (h DeleteMany[ID]) Handler(ctx context.Context, in *IDsInput[ID]) (*struct{}, error)

func (DeleteMany[ID]) Register

func (h DeleteMany[ID]) Register(_ *echo.Echo, api huma.API)

type ErrorTransformerFunc

type ErrorTransformerFunc func(context.Context, error) error

type Handler added in v0.0.5

type Handler interface {
	Area() string
	Version() string
	Register(*echo.Echo, huma.API)
}

type IDInput

type IDInput[ID any] struct {
	ID ID `path:"id"`
}

type IDsInput

type IDsInput[ID any] struct {
	Body struct {
		IDs []ID `json:"ids" required:"true" minItems:"1" nullable:"false"`
	}
}

type List

type List[M any] struct {
	Finder           func(context.Context, *cr.Criteria) ([]M, int, error)
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewList

func NewList[T any](
	finder func(context.Context, *cr.Criteria) ([]T, int, error),
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) List[T]

func (List[M]) Handler

func (h List[M]) Handler(ctx context.Context, in *ListInput) (*Response[ListOutput[M]], error)

func (List[M]) Register

func (h List[M]) Register(_ *echo.Echo, api huma.API)

type ListInput

type ListInput struct {
	Page   int    `query:"page" json:"page,omitempty" yaml:"page,omitempty" required:"false"`
	Limit  int    `query:"limit" json:"limit,omitempty" yaml:"limit,omitempty" required:"false"`
	Sort   string `query:"sort" json:"sort,omitempty" yaml:"sort,omitempty" required:"false"`
	Filter string `query:"filter" json:"filter,omitempty" yaml:"filter,omitempty" required:"false"`
}

func (*ListInput) Resolve

func (in *ListInput) Resolve(huma.Context) []error

type ListOutput

type ListOutput[E any] struct {
	ListInput
	Items []E `json:"items,omitempty" yaml:"items,omitempty" required:"false"`
	Total int `json:"total,omitempty" yaml:"total,omitempty" required:"false"`
}

type Middleware added in v0.0.5

type Middleware struct {
	Name       string
	Middleware func(huma.API) func(huma.Context, func(huma.Context))
}

func AuthorizationMiddleware added in v0.0.5

func AuthorizationMiddleware(authorizer Authorizer, logger *zap.Logger) Middleware

func NewMiddleware added in v0.0.5

func NewMiddleware(name string, middleware func(huma.API) func(huma.Context, func(huma.Context))) Middleware

type Option

type Option func(*huma.Operation)

func WithAddPath

func WithAddPath(path string) Option

func WithAddTags

func WithAddTags(tags ...string) Option

func WithDefaultStatus

func WithDefaultStatus(status int) Option

func WithDescription

func WithDescription(description string) Option

func WithMetadata

func WithMetadata(metadata map[string]any) Option

func WithMetadataItem

func WithMetadataItem(key string, value any) Option

func WithMethod

func WithMethod(method string) Option

func WithOperationID

func WithOperationID(operationID string) Option

func WithPath

func WithPath(path string) Option

func WithSecurity

func WithSecurity(security []map[string][]string) Option

func WithSummary

func WithSummary(summary string) Option

func WithTags

func WithTags(tags ...string) Option

type Read

type Read[M any, ID any] struct {
	Finder           func(context.Context, ID) (M, error)
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewRead

func NewRead[T any, ID any](
	finder func(context.Context, ID) (T, error),
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) Read[T, ID]

func (Read[M, ID]) Handler

func (h Read[M, ID]) Handler(ctx context.Context, in *IDInput[ID]) (*Response[M], error)

func (Read[M, ID]) Register

func (h Read[M, ID]) Register(_ *echo.Echo, api huma.API)

type Response

type Response[B any] struct {
	Body B
}

type Update

type Update[B interface {
	Decode(context.Context, *M) error
}, M any, ID any] struct {
	Finder           func(context.Context, ID) (M, error)
	Saver            func(context.Context, *M) error
	ErrorTransformer ErrorTransformerFunc
	Operation        huma.Operation
}

func NewUpdate

func NewUpdate[B interface {
	Decode(context.Context, *M) error
}, M any, ID any](
	finder func(context.Context, ID) (M, error),
	saver func(context.Context, *M) error,
	errorTransformer ErrorTransformerFunc,
	operation huma.Operation,
) Update[B, M, ID]

func (Update[B, M, ID]) Handler

func (h Update[B, M, ID]) Handler(ctx context.Context, in *UpdateInput[B, ID]) (*struct{}, error)

func (Update[B, M, ID]) Register

func (h Update[B, M, ID]) Register(_ *echo.Echo, api huma.API)

type UpdateInput

type UpdateInput[B any, ID any] struct {
	ID   ID `path:"id"`
	Body B
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL