diff --git a/client.go b/client.go index db54f83..804024e 100644 --- a/client.go +++ b/client.go @@ -36,6 +36,7 @@ import ( // closed. var ErrClosed = errors.New("ttrpc: closed") +// Client for a ttrpc server type Client struct { codec codec conn net.Conn @@ -50,14 +51,17 @@ type Client struct { interceptor UnaryClientInterceptor } +// ClientOpts configures a client type ClientOpts func(c *Client) +// WithOnClose sets the close func whenever the client's Close() method is called func WithOnClose(onClose func()) ClientOpts { return func(c *Client) { c.closeFunc = onClose } } +// WithUnaryClientInterceptor sets the provided client interceptor func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts { return func(c *Client) { c.interceptor = i diff --git a/config.go b/config.go index 86b6307..6a53c11 100644 --- a/config.go +++ b/config.go @@ -23,6 +23,7 @@ type serverConfig struct { interceptor UnaryServerInterceptor } +// ServerOpt for configuring a ttrpc server type ServerOpt func(*serverConfig) error // WithServerHandshaker can be passed to NewServer to ensure that the @@ -39,6 +40,7 @@ func WithServerHandshaker(handshaker Handshaker) ServerOpt { } } +// WithUnaryServerInterceptor sets the provided interceptor on the server func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt { return func(c *serverConfig) error { if c.interceptor != nil { diff --git a/interceptor.go b/interceptor.go index 562c1e1..c1219da 100644 --- a/interceptor.go +++ b/interceptor.go @@ -18,20 +18,27 @@ package ttrpc import "context" +// UnaryServerInfo provides information about the server request type UnaryServerInfo struct { FullMethod string } +// UnaryClientInfo provides information about the client request type UnaryClientInfo struct { FullMethod string } +// Unmarshaler contains the server request data and allows it to be unmarshaled +// into a concrete type type Unmarshaler func(interface{}) error +// Invoker invokes the client's request and response from the ttrpc server type Invoker func(context.Context, *Request, *Response) error +// UnaryServerInterceptor specifies the interceptor function for server request/response type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, Method) (interface{}, error) +// UnaryClientInterceptor specifies the interceptor function for client request/response type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, info *UnaryServerInfo, method Method) (interface{}, error) {