rpc

package
v0.0.0-...-8f77053 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMiddleware

func DefaultMiddleware() []rf.MiddlewareFunc

Types

type Handler

type Handler[Req any, Res comparable] struct {
	// contains filtered or unexported fields
}

Handler is an instance of a JSON based, POST only, jsonschema validated handler. This handler type is very opinionated and uses the yael package for handling errors.

func NewHandler

func NewHandler[Req any, Res comparable](
	fn RPCHandlerFunc[Req, Res],
	schema gojsonschema.JSONLoader,
) *Handler[Req, Res]

NewHandler returns a handler instance with the provided handler function and jsonschema to validate the request with. The 'fn' argument provided must be a function with a signature like so:

func Example(ctx context.Context, req RequestType) (ResponseType, error)

Any mismatch against the above format will result in a panic

func (*Handler[Req, Res]) Error

func (rpc *Handler[Req, Res]) Error() rf.ErrorHandlerFunc

func (*Handler[Req, Res]) Handle

func (h *Handler[Req, Res]) Handle() rf.HandlerFunc

type RPCHandlerFunc

type RPCHandlerFunc[Req any, Res comparable] func(context.Context, Req) (Res, error)

Jump to

Keyboard shortcuts

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