endpoint

package
v1.31.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 23 Imported by: 0

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 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

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 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(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, 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