rpc

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRequestHandler

func CheckRequestHandler[request any, response any](checkFunc func(request) (bool, string)) func(ctx *Context[request, response])

func CheckResponseHandler

func CheckResponseHandler[request any, response any](checkFunc func(response) (bool, string)) func(ctx *Context[request, response])

func ExecuteChain

func ExecuteChain[request any, response any](handlers Chain[request, response], ctx context.Context, req request, resp response) (result response, err error)

func LogInputAndOutputHandler

func LogInputAndOutputHandler[request any, response any](log logger.Logger, service string, handler string) func(ctx *Context[request, response])

func RecoveryHandler

func RecoveryHandler[request any, response any](log logger.Logger, service string, handler string) func(ctx *Context[request, response])

func RequestLimiterHandler

func RequestLimiterHandler[request any, response any](rpd, rpm, rps int) func(ctx *Context[request, response])

func RequestLimiterHandlerWithFn

func RequestLimiterHandlerWithFn[request any, response any](rpd, rpm, rps int, _ func(request) (response, error)) func(ctx *Context[request, response])

Types

type Chain

type Chain[request any, response any] []Handler[request, response]

func NewChain

func NewChain[request any, response any](handlers ...Handler[request, response]) Chain[request, response]

func (Chain[request, response]) AddHandlerBack added in v1.2.9

func (c Chain[request, response]) AddHandlerBack(h ...Handler[request, response]) Chain[request, response]

func (Chain[request, response]) AddHandlerFront added in v1.2.9

func (c Chain[request, response]) AddHandlerFront(h ...Handler[request, response]) Chain[request, response]

func (Chain[request, response]) Run

func (c Chain[request, response]) Run(ctx *Context[request, response])

type CheckRequestFailedError

type CheckRequestFailedError struct {
	Reason string
}

func NewCheckRequestFailedError

func NewCheckRequestFailedError(reason string) CheckRequestFailedError

func (CheckRequestFailedError) Error

func (e CheckRequestFailedError) Error() string

type CheckResponseFailedError

type CheckResponseFailedError struct {
	Reason string
}

func NewCheckResponseFailedError

func NewCheckResponseFailedError(reason string) CheckResponseFailedError

func (CheckResponseFailedError) Error

func (e CheckResponseFailedError) Error() string

type Context

type Context[request any, response any] struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext[request any, response any](ctx context.Context, req request, resp response) *Context[request, response]

func (*Context[request, response]) Abort

func (c *Context[request, response]) Abort()

func (*Context[request, response]) Deadline

func (c *Context[request, response]) Deadline() (deadline time.Time, ok bool)

func (*Context[request, response]) Done

func (c *Context[request, response]) Done() <-chan struct{}

func (*Context[request, response]) Err

func (c *Context[request, response]) Err() error

func (*Context[request, response]) Error

func (c *Context[request, response]) Error() error

func (*Context[request, response]) GetContext

func (c *Context[request, response]) GetContext() context.Context

func (*Context[request, response]) GetContextClientIP

func (c *Context[request, response]) GetContextClientIP() (ip string, err error)

func (*Context[request, response]) GetRequest

func (c *Context[request, response]) GetRequest() request

func (*Context[request, response]) GetResponse

func (c *Context[request, response]) GetResponse() response

func (*Context[request, response]) IsAborted

func (c *Context[request, response]) IsAborted() bool

func (*Context[request, response]) Next

func (c *Context[request, response]) Next()

func (*Context[request, response]) SetContext

func (c *Context[request, response]) SetContext(ctx context.Context)

func (*Context[request, response]) SetError

func (c *Context[request, response]) SetError(err error)

func (*Context[request, response]) SetRequest

func (c *Context[request, response]) SetRequest(req request)

func (*Context[request, response]) SetResponse

func (c *Context[request, response]) SetResponse(resp response)

func (*Context[request, response]) SetResult

func (c *Context[request, response]) SetResult(resp response, err error)

func (*Context[request, response]) TraceID

func (c *Context[request, response]) TraceID() string

func (*Context[request, response]) Value

func (c *Context[request, response]) Value(key any) any

type Engine

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

func NewEngine

func NewEngine() *Engine

func (*Engine) AddService

func (e *Engine) AddService(services ...Service)

func (*Engine) Serve

func (e *Engine) Serve(address string) (err error)

func (*Engine) ServeAsync

func (e *Engine) ServeAsync(address string, ex chan struct{}) (exitChan chan error)

func (*Engine) Serving

func (e *Engine) Serving() bool

type GetRPCClientIPFailedError

type GetRPCClientIPFailedError struct{}

func NewGetRPCClientIPFailedError

func NewGetRPCClientIPFailedError() GetRPCClientIPFailedError

func (GetRPCClientIPFailedError) Error

type Handler

type Handler[request any, response any] func(ctx *Context[request, response])

type InvalidIPAddressError

type InvalidIPAddressError struct {
	IPAddress string
}

func NewInvalidIPAddressError

func NewInvalidIPAddressError(ipAddress string) InvalidIPAddressError

func (InvalidIPAddressError) Error

func (e InvalidIPAddressError) Error() string

type Marshaller

type Marshaller interface {
	Marshal(request any) ([]byte, error)
	Unmarshal(data []byte, response any) error
}

func NewJsonMarshaller

func NewJsonMarshaller() Marshaller

func NewYamlMarshaller

func NewYamlMarshaller() Marshaller

type RequestLimiterError

type RequestLimiterError struct {
	Reason string
}

func NewRequestLimiterError

func NewRequestLimiterError(reason string) RequestLimiterError

func (RequestLimiterError) Error

func (e RequestLimiterError) Error() string

type ServerAlreadyServingError

type ServerAlreadyServingError struct {
	Address string
}

func NewServerAlreadyServingError

func NewServerAlreadyServingError(address string) ServerAlreadyServingError

func (ServerAlreadyServingError) Error

type Service

type Service interface {
	Initialization()
	BindEngine(conn *grpc.Server)
}

type UnsupportedNetworkError

type UnsupportedNetworkError struct {
	Network string
}

func NewUnsupportedNetworkError

func NewUnsupportedNetworkError(network string) UnsupportedNetworkError

func (UnsupportedNetworkError) Error

func (e UnsupportedNetworkError) Error() string

Jump to

Keyboard shortcuts

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