water

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 8 Imported by: 6

README

water

上善若水,水善利万物而不争

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodeRequestFunc

type DecodeRequestFunc func(context.Context, interface{}) (request interface{}, err error)

DecodeRequestFunc extracts a user-domain request object from a gRPC request. It's designed to be used in gRPC servers, for server-side endpoints. One straightforward DecodeRequestFunc could be something that decodes from the gRPC request message to the concrete request type.

type EncodeResponseFunc

type EncodeResponseFunc func(context.Context, interface{}) (response interface{}, err error)

EncodeResponseFunc encodes the passed response object to the gRPC response message. It's designed to be used in gRPC servers, for server-side endpoints. One straightforward EncodeResponseFunc could be something that encodes the object directly to the gRPC response message.

type Endpoint

type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error)

Endpoint is the fundamental building block of servers and clients. It represents a single RPC method.

func PrintRpcCall

func PrintRpcCall(logger grpclog.DepthLoggerV2, e Endpoint) Endpoint

type ErrorHandler

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

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

type ErrorHandlerFunc

type ErrorHandlerFunc func(ctx context.Context, err error)

The ErrorHandlerFunc type is an adapter to allow the use of ordinary function as ErrorHandler. If f is a function with the appropriate signature, ErrorHandlerFunc(f) is a ErrorHandler that calls f.

func (ErrorHandlerFunc) Handle

func (f ErrorHandlerFunc) Handle(ctx context.Context, err error)

Handle calls f(ctx, err).

type Handler

type Handler interface {
	ServeGRPC(ctx context.Context, request interface{}) (context.Context, interface{}, error)
}

Handler which should be called from the gRPC binding of the service implementation. The incoming request parameter, and returned response parameter, are both gRPC types, not user-domain.

type LogErrorHandler

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

LogErrorHandler is a transport error handler implementation which logs an error.

func NewLogErrorHandler

func NewLogErrorHandler(com string) *LogErrorHandler

func (*LogErrorHandler) Handle

func (h *LogErrorHandler) Handle(ctx context.Context, err error)

type Server

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

Server wraps an endpoint and implements grpc.Handler.

func NewHandler

func NewHandler(svc Service, options ...ServerOption) *Server

func NewServer

func NewServer(
	e Endpoint,
	dec DecodeRequestFunc,
	enc EncodeResponseFunc,
	options ...ServerOption,
) *Server

NewServer constructs a new server, which implements wraps the provided endpoint and implements the Handler interface. Consumers should write bindings that adapt the concrete gRPC methods from their compiled protobuf definitions to individual handlers. Request and response objects are from the caller business domain, not gRPC request and reply types.

func (Server) ServeGRPC

func (s Server) ServeGRPC(ctx context.Context, req interface{}) (retctx context.Context, resp interface{}, err error)

type ServerFinalizerFunc

type ServerFinalizerFunc func(ctx context.Context, err error)

ServerFinalizerFunc can be used to perform work at the end of an gRPC request, after the response has been written to the client.

type ServerOption

type ServerOption func(*Server)

ServerOption sets an optional parameter for servers.

func ServerAfter

func ServerAfter(after ...ServerResponseFunc) ServerOption

ServerAfter functions are executed on the gRPC response writer after the endpoint is invoked, but before anything is written to the client.

func ServerBefore

func ServerBefore(before ...ServerRequestFunc) ServerOption

ServerBefore functions are executed on the gRPC request object before the request is decoded.

type ServerRequestFunc

type ServerRequestFunc func(context.Context, metadata.MD) context.Context

ServerRequestFunc may take information from the received metadata header and use it to place items in the request scoped context. ServerRequestFuncs are executed prior to invoking the endpoint.

type ServerResponseFunc

type ServerResponseFunc func(ctx context.Context, header *metadata.MD, trailer *metadata.MD) context.Context

ServerResponseFunc may take information from a request context and use it to manipulate the gRPC response metadata headers and trailers. ResponseFuncs are only executed in servers, after invoking the endpoint but prior to writing a response.

type Service

type Service interface {
	Endpoint() Endpoint
	DecodeRequest(ctx context.Context, req interface{}) (interface{}, error)
	EncodeResponse(ctx context.Context, resp interface{}) (interface{}, error)
	ServerBefore() ServerOption
	ServerAfter() ServerOption
	GetLogger() grpclog.DepthLoggerV2
	Name() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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