endpoint

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyLogger

func BodyLogger(logger log.Logger) grpc.Middleware

func ErrorHandler

func ErrorHandler(logger log.Logger) grpc.Middleware

func Metrics

func Metrics(storage MetricStorage) grpc.Middleware

func Recovery

func Recovery() grpc.Middleware

func RequestId

func RequestId() grpc.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, message *isp.Message) (*isp.Message, error)

type GrpcError

type GrpcError interface {
	GrpcStatusError() error
}

type JsonRequestExtractor

type JsonRequestExtractor struct {
	Validator Validator
}

func (JsonRequestExtractor) Extract

func (j JsonRequestExtractor) Extract(ctx context.Context, message *isp.Message, reqBodyType reflect.Type) (reflect.Value, error)

type JsonResponseMapper

type JsonResponseMapper struct {
}

func (JsonResponseMapper) Map

func (j JsonResponseMapper) Map(result any) (*isp.Message, error)

type MetricStorage

type MetricStorage interface {
	ObserveDuration(method string, duration time.Duration)
	ObserveRequestBodySize(method string, size int)
	ObserveResponseBodySize(method string, size int)
	CountStatusCode(endpoint string, code codes.Code)
}

type ParamBuilder

type ParamBuilder func(ctx context.Context, message *isp.Message) (any, error)

type ParamMapper

type ParamMapper struct {
	Type    string
	Builder ParamBuilder
}

func AuthDataParam

func AuthDataParam() ParamMapper

func ContextParam

func ContextParam() ParamMapper

type RequestBodyExtractor

type RequestBodyExtractor interface {
	Extract(ctx context.Context, message *isp.Message, reqBodyType reflect.Type) (reflect.Value, error)
}

type ResponseBodyMapper

type ResponseBodyMapper interface {
	Map(result any) (*isp.Message, 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   []grpc.Middleware
}

func DefaultWrapper

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

func NewWrapper

func NewWrapper(
	paramMappers []ParamMapper,
	bodyExtractor RequestBodyExtractor,
	bodyMapper ResponseBodyMapper,
) Wrapper

func (Wrapper) Endpoint

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

func (Wrapper) WithMiddlewares

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

Jump to

Keyboard shortcuts

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