Add godocs for interceptors
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
e409d7d775
commit
de8faac08b
@ -36,6 +36,7 @@ import (
|
|||||||
// closed.
|
// closed.
|
||||||
var ErrClosed = errors.New("ttrpc: closed")
|
var ErrClosed = errors.New("ttrpc: closed")
|
||||||
|
|
||||||
|
// Client for a ttrpc server
|
||||||
type Client struct {
|
type Client struct {
|
||||||
codec codec
|
codec codec
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
@ -50,14 +51,17 @@ type Client struct {
|
|||||||
interceptor UnaryClientInterceptor
|
interceptor UnaryClientInterceptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientOpts configures a client
|
||||||
type ClientOpts func(c *Client)
|
type ClientOpts func(c *Client)
|
||||||
|
|
||||||
|
// WithOnClose sets the close func whenever the client's Close() method is called
|
||||||
func WithOnClose(onClose func()) ClientOpts {
|
func WithOnClose(onClose func()) ClientOpts {
|
||||||
return func(c *Client) {
|
return func(c *Client) {
|
||||||
c.closeFunc = onClose
|
c.closeFunc = onClose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithUnaryClientInterceptor sets the provided client interceptor
|
||||||
func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts {
|
func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts {
|
||||||
return func(c *Client) {
|
return func(c *Client) {
|
||||||
c.interceptor = i
|
c.interceptor = i
|
||||||
|
@ -23,6 +23,7 @@ type serverConfig struct {
|
|||||||
interceptor UnaryServerInterceptor
|
interceptor UnaryServerInterceptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServerOpt for configuring a ttrpc server
|
||||||
type ServerOpt func(*serverConfig) error
|
type ServerOpt func(*serverConfig) error
|
||||||
|
|
||||||
// WithServerHandshaker can be passed to NewServer to ensure that the
|
// 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 {
|
func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt {
|
||||||
return func(c *serverConfig) error {
|
return func(c *serverConfig) error {
|
||||||
if c.interceptor != nil {
|
if c.interceptor != nil {
|
||||||
|
@ -18,20 +18,27 @@ package ttrpc
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
// UnaryServerInfo provides information about the server request
|
||||||
type UnaryServerInfo struct {
|
type UnaryServerInfo struct {
|
||||||
FullMethod string
|
FullMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnaryClientInfo provides information about the client request
|
||||||
type UnaryClientInfo struct {
|
type UnaryClientInfo struct {
|
||||||
FullMethod string
|
FullMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unmarshaler contains the server request data and allows it to be unmarshaled
|
||||||
|
// into a concrete type
|
||||||
type Unmarshaler func(interface{}) error
|
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
|
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)
|
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
|
type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error
|
||||||
|
|
||||||
func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, info *UnaryServerInfo, method Method) (interface{}, error) {
|
func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, info *UnaryServerInfo, method Method) (interface{}, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user