httptransport

package
v1.0.0-beta.153 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorEncoder

type ErrorEncoder func(ctx context.Context, err error, w http.ResponseWriter, r *http.Request) bool

ErrorEncoder is responsible for encoding an error to the ResponseWriter. Users are encouraged to use custom ErrorEncoders to encode HTTP errors to their clients, and will likely want to pass and check for their own error types. See the example shipping/handling service.

type ErrorHandler

type ErrorHandler interface {
	HandleContext(ctx context.Context, err error)
}

ErrorHandler receives a transport error to be processed for diagnostic purposes. Usually this means logging the error.

type Handler

type Handler[Request any, Response any] interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	Chain(outer operation.Middleware[Request, Response], others ...operation.Middleware[Request, Response]) Handler[Request, Response]
}

func NewHandler

func NewHandler[Request any, Response any](
	requestDecoder RequestDecoder[Request],
	op operation.Operation[Request, Response],
	responseEncoder ResponseEncoder[Response],

	options ...HandlerOption,
) Handler[Request, Response]

NewHandler returns a new HTTP handler that wraps the given operation.Operation.

type HandlerOption

type HandlerOption interface {
	// contains filtered or unexported methods
}

func AppendOptions

func AppendOptions(base []HandlerOption, items ...HandlerOption) []HandlerOption

func WithErrorEncoder

func WithErrorEncoder(errorEncoder ErrorEncoder) HandlerOption

func WithErrorHandler

func WithErrorHandler(errorHandler ErrorHandler) HandlerOption

func WithOperationName

func WithOperationName(name string) HandlerOption

func WithOperationNameFunc

func WithOperationNameFunc(fn func(ctx context.Context) string) HandlerOption

type HandlerWithArgs

type HandlerWithArgs[Request any, Response any, ArgType any] interface {
	With(ArgType) Handler[Request, Response]
	Chain(outer operation.Middleware[Request, Response], others ...operation.Middleware[Request, Response]) HandlerWithArgs[Request, Response, ArgType]
}

func NewHandlerWithArgs

func NewHandlerWithArgs[Request any, Response any, ArgType any](
	requestDecoder RequestDecoderWithArgs[Request, ArgType],
	op operation.Operation[Request, Response],
	responseEncoder ResponseEncoder[Response],

	options ...HandlerOption,
) HandlerWithArgs[Request, Response, ArgType]

type RequestDecoder

type RequestDecoder[Request any] func(ctx context.Context, r *http.Request) (Request, error)

type RequestDecoderWithArgs

type RequestDecoderWithArgs[Request any, ArgType any] func(ctx context.Context, r *http.Request, arg ArgType) (Request, error)

type ResponseEncoder

type ResponseEncoder[Response any] func(ctx context.Context, w http.ResponseWriter, response Response) error

type SelfEncodingError

type SelfEncodingError interface {
	EncodeError(ctx context.Context, w http.ResponseWriter) bool
}

Jump to

Keyboard shortcuts

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