endpoint

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLog

func DefaultLog(logger log.Logger) http2.Middleware

func ErrorHandler

func ErrorHandler(logger log.Logger) http2.Middleware

func Log

func Log(logger log.Logger, availableContentTypes []string) http2.Middleware

func MaxRequestBodySize

func MaxRequestBodySize(maxBytes int64) http2.Middleware

func Recovery

func Recovery() http2.Middleware

func RequestId

func RequestId() http2.Middleware

Types

type Caller

type Caller struct {
	// contains filtered or unexported fields
}

func NewCaller

func NewCaller(
	f any,
	bodyExtractor RequestBinder,
	bodyMapper ResponseBodyMapper,
	paramMappers map[string]ParamMapper,
) (*Caller, error)

func (*Caller) Handle

func (h *Caller) Handle(ctx context.Context, w http.ResponseWriter, r *http.Request) error

type DefaultResponseMapper

type DefaultResponseMapper struct {
	JsonResponseMapper
}

func (DefaultResponseMapper) Map

type HttpError

type HttpError interface {
	WriteError(w http.ResponseWriter) error
}

type JsonResponseMapper

type JsonResponseMapper struct {
}

func (JsonResponseMapper) Map

func (j JsonResponseMapper) Map(result any, w http.ResponseWriter) error

type ParamBuilder

type ParamBuilder func(ctx context.Context, w http.ResponseWriter, r *http.Request) (any, error)

type ParamMapper

type ParamMapper struct {
	Type    string
	Builder ParamBuilder
}

func BearerTokenParam

func BearerTokenParam() ParamMapper

func ContextParam

func ContextParam() ParamMapper

func RangeParam

func RangeParam() ParamMapper

func RequestParam

func RequestParam() ParamMapper

func ResponseWriterParam

func ResponseWriterParam() ParamMapper

type RequestBinder

type RequestBinder interface {
	Bind(ctx context.Context, contentType string, r *http.Request, reqBodyType reflect.Type) (reflect.Value, error)
}

type ResponseBodyMapper

type ResponseBodyMapper interface {
	Map(result any, w http.ResponseWriter) error
}

type ResponseWriter

type ResponseWriter interface {
	Write(w http.ResponseWriter) error
}

type Wrapper

type Wrapper struct {
	ParamMappers map[string]ParamMapper
	Binder       RequestBinder
	BodyMapper   ResponseBodyMapper
	Middlewares  []http2.Middleware
	Logger       log.Logger
}

func DefaultWrapper

func DefaultWrapper(logger log.Logger, restMiddlewares ...http.Middleware) Wrapper

func NewWrapper

func NewWrapper(
	paramMappers []ParamMapper,
	binder RequestBinder,
	bodyMapper ResponseBodyMapper,
	logger log.Logger,
) Wrapper

func (Wrapper) Endpoint

func (m Wrapper) Endpoint(f any) http.HandlerFunc

func (Wrapper) WithMiddlewares

func (m Wrapper) WithMiddlewares(middlewares ...http2.Middleware) Wrapper

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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