endpoint

package
v1.41.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 23 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(logger log.Logger) http2.Middleware

func MaxRequestBodySize

func MaxRequestBodySize(maxBytes int64) http2.Middleware

func Metrics

func Metrics(storage *http_metrics.ServerStorage) 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 RequestBodyExtractor,
	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 HttpError

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

type JsonRequestExtractor

type JsonRequestExtractor struct {
	Validator Validator
}

func (JsonRequestExtractor) Extract

func (j JsonRequestExtractor) Extract(ctx context.Context, reader io.Reader, reqBodyType reflect.Type) (reflect.Value, error)

type JsonResponseMapper

type JsonResponseMapper struct {
}

func (JsonResponseMapper) Map

type LogMiddleware added in v1.40.0

type LogMiddleware http2.Middleware

func Log

func Log(logger log.Logger, logBody bool) LogMiddleware

func LogWithContentTypes added in v1.40.0

func LogWithContentTypes(logger log.Logger, logBody bool, logBodyContentTypes []string) LogMiddleware

func Noop added in v1.40.0

func Noop() LogMiddleware

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 ContextParam

func ContextParam() ParamMapper

func RequestParam

func RequestParam() ParamMapper

func ResponseWriterParam

func ResponseWriterParam() ParamMapper

type RequestBodyExtractor

type RequestBodyExtractor interface {
	Extract(ctx context.Context, reader io.Reader, reqBodyType reflect.Type) (reflect.Value, error)
}

type ResponseBodyMapper

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

type Validator

type Validator interface {
	Validate(value any) (bool, map[string]string)
}

type Wrapper

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

func DefaultWrapper

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

func NewWrapper

func NewWrapper(
	paramMappers []ParamMapper,
	bodyExtractor RequestBodyExtractor,
	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