Skip to content

Commit de8faac

Browse files
committed
Add godocs for interceptors
Signed-off-by: Michael Crosby <[email protected]>
1 parent e409d7d commit de8faac

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
// closed.
3737
var ErrClosed = errors.New("ttrpc: closed")
3838

39+
// Client for a ttrpc server
3940
type Client struct {
4041
codec codec
4142
conn net.Conn
@@ -50,14 +51,17 @@ type Client struct {
5051
interceptor UnaryClientInterceptor
5152
}
5253

54+
// ClientOpts configures a client
5355
type ClientOpts func(c *Client)
5456

57+
// WithOnClose sets the close func whenever the client's Close() method is called
5558
func WithOnClose(onClose func()) ClientOpts {
5659
return func(c *Client) {
5760
c.closeFunc = onClose
5861
}
5962
}
6063

64+
// WithUnaryClientInterceptor sets the provided client interceptor
6165
func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts {
6266
return func(c *Client) {
6367
c.interceptor = i

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type serverConfig struct {
2323
interceptor UnaryServerInterceptor
2424
}
2525

26+
// ServerOpt for configuring a ttrpc server
2627
type ServerOpt func(*serverConfig) error
2728

2829
// WithServerHandshaker can be passed to NewServer to ensure that the
@@ -39,6 +40,7 @@ func WithServerHandshaker(handshaker Handshaker) ServerOpt {
3940
}
4041
}
4142

43+
// WithUnaryServerInterceptor sets the provided interceptor on the server
4244
func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt {
4345
return func(c *serverConfig) error {
4446
if c.interceptor != nil {

interceptor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@ package ttrpc
1818

1919
import "context"
2020

21+
// UnaryServerInfo provides information about the server request
2122
type UnaryServerInfo struct {
2223
FullMethod string
2324
}
2425

26+
// UnaryClientInfo provides information about the client request
2527
type UnaryClientInfo struct {
2628
FullMethod string
2729
}
2830

31+
// Unmarshaler contains the server request data and allows it to be unmarshaled
32+
// into a concrete type
2933
type Unmarshaler func(interface{}) error
3034

35+
// Invoker invokes the client's request and response from the ttrpc server
3136
type Invoker func(context.Context, *Request, *Response) error
3237

38+
// UnaryServerInterceptor specifies the interceptor function for server request/response
3339
type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, Method) (interface{}, error)
3440

41+
// UnaryClientInterceptor specifies the interceptor function for client request/response
3542
type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error
3643

3744
func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, info *UnaryServerInfo, method Method) (interface{}, error) {

0 commit comments

Comments
 (0)