package ttrpc
import "github.com/containerd/ttrpc"
Index ¶
- Variables
- func GetMetadataValue(ctx context.Context, name string) (string, bool)
- func WithMetadata(ctx context.Context, md MD) context.Context
- type Client
- func NewClient(conn net.Conn, opts ...ClientOpts) *Client
- func (c *Client) Call(ctx context.Context, service, method string, req, resp interface{}) error
- func (c *Client) Close() error
- func (c *Client) UserOnCloseWait(ctx context.Context) error
- type ClientOpts
- func WithOnClose(onClose func()) ClientOpts
- func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts
- type Handshaker
- type Invoker
- type KeyValue
- type MD
- func GetMetadata(ctx context.Context) (MD, bool)
- func (m MD) Append(key string, values ...string)
- func (m MD) Get(key string) ([]string, bool)
- func (m MD) Set(key string, values ...string)
- type Method
- type Request
- type Response
- type Server
- func NewServer(opts ...ServerOpt) (*Server, error)
- func (s *Server) Close() error
- func (s *Server) Register(name string, methods map[string]Method)
- func (s *Server) Serve(ctx context.Context, l net.Listener) error
- func (s *Server) Shutdown(ctx context.Context) error
- type ServerOpt
- func WithServerHandshaker(handshaker Handshaker) ServerOpt
- func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt
- type ServiceDesc
- type StringList
- func (r *StringList) ProtoMessage()
- func (r *StringList) Reset()
- func (r *StringList) String() string
- type UnaryClientInfo
- type UnaryClientInterceptor
- type UnaryServerInfo
- type UnaryServerInterceptor
- type Unmarshaler
Variables ¶
ErrClosed is returned by client methods when the underlying connection is closed.
Functions ¶
func GetMetadataValue ¶
GetMetadataValue gets a specific metadata value by name from context.Context
func WithMetadata ¶
WithMetadata attaches metadata map to a context.Context
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for a ttrpc server
func NewClient ¶
func NewClient(conn net.Conn, opts ...ClientOpts) *Client
func (*Client) Call ¶
func (*Client) Close ¶
func (*Client) UserOnCloseWait ¶
UserOnCloseWait is used to blocks untils the user's on-close callback finishes.
type ClientOpts ¶
type ClientOpts func(c *Client)
ClientOpts configures a client
func WithOnClose ¶
func WithOnClose(onClose func()) ClientOpts
WithOnClose sets the close func whenever the client's Close() method is called
func WithUnaryClientInterceptor ¶
func WithUnaryClientInterceptor(i UnaryClientInterceptor) ClientOpts
WithUnaryClientInterceptor sets the provided client interceptor
type Handshaker ¶
type Handshaker interface { // Handshake should confirm or decorate a connection that may be incoming // to a server or outgoing from a client. // // If this returns without an error, the caller should use the connection // in place of the original connection. // // The second return value can contain credential specific data, such as // unix socket credentials or TLS information. // // While we currently only have implementations on the server-side, this // interface should be sufficient to implement similar handshakes on the // client-side. Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) }
Handshaker defines the interface for connection handshakes performed on the server or client when first connecting.
type Invoker ¶
Invoker invokes the client's request and response from the ttrpc server
type KeyValue ¶
type KeyValue struct { Key string `protobuf:"bytes,1,opt,name=key,proto3"` Value string `protobuf:"bytes,2,opt,name=value,proto3"` }
func (*KeyValue) ProtoMessage ¶
func (*KeyValue) ProtoMessage()
func (*KeyValue) Reset ¶
func (m *KeyValue) Reset()
func (*KeyValue) String ¶
type MD ¶
MD is the user type for ttrpc metadata
func GetMetadata ¶
GetMetadata retrieves metadata from context.Context (previously attached with WithMetadata)
func (MD) Append ¶
Append appends additional values to the given key.
func (MD) Get ¶
Get returns the metadata for a given key when they exist. If there is no metadata, a nil slice and false are returned.
func (MD) Set ¶
Set sets the provided values for a given key. The values will overwrite any existing values. If no values provided, a key will be deleted.
type Method ¶
type Request ¶
type Request struct { Service string `protobuf:"bytes,1,opt,name=service,proto3"` Method string `protobuf:"bytes,2,opt,name=method,proto3"` Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3"` TimeoutNano int64 `protobuf:"varint,4,opt,name=timeout_nano,proto3"` Metadata []*KeyValue `protobuf:"bytes,5,rep,name=metadata,proto3"` }
func (*Request) ProtoMessage ¶
func (r *Request) ProtoMessage()
func (*Request) Reset ¶
func (r *Request) Reset()
func (*Request) String ¶
type Response ¶
type Response struct { Status *spb.Status `protobuf:"bytes,1,opt,name=status,proto3"` Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3"` }
func (*Response) ProtoMessage ¶
func (r *Response) ProtoMessage()
func (*Response) Reset ¶
func (r *Response) Reset()
func (*Response) String ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func (*Server) Close ¶
Close the server without waiting for active connections.
func (*Server) Register ¶
func (*Server) Serve ¶
func (*Server) Shutdown ¶
type ServerOpt ¶
type ServerOpt func(*serverConfig) error
ServerOpt for configuring a ttrpc server
func WithServerHandshaker ¶
func WithServerHandshaker(handshaker Handshaker) ServerOpt
WithServerHandshaker can be passed to NewServer to ensure that the handshaker is called before every connection attempt.
Only one handshaker is allowed per server.
func WithUnaryServerInterceptor ¶
func WithUnaryServerInterceptor(i UnaryServerInterceptor) ServerOpt
WithUnaryServerInterceptor sets the provided interceptor on the server
type ServiceDesc ¶
type StringList ¶
type StringList struct { List []string `protobuf:"bytes,1,rep,name=list,proto3"` }
func (*StringList) ProtoMessage ¶
func (r *StringList) ProtoMessage()
func (*StringList) Reset ¶
func (r *StringList) Reset()
func (*StringList) String ¶
func (r *StringList) String() string
type UnaryClientInfo ¶
type UnaryClientInfo struct { FullMethod string }
UnaryClientInfo provides information about the client request
type UnaryClientInterceptor ¶
type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error
UnaryClientInterceptor specifies the interceptor function for client request/response
type UnaryServerInfo ¶
type UnaryServerInfo struct { FullMethod string }
UnaryServerInfo provides information about the server request
type UnaryServerInterceptor ¶
type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, Method) (interface{}, error)
UnaryServerInterceptor specifies the interceptor function for server request/response
type Unmarshaler ¶
type Unmarshaler func(interface{}) error
Unmarshaler contains the server request data and allows it to be unmarshaled into a concrete type
Source Files ¶
channel.go client.go codec.go config.go handshake.go interceptor.go metadata.go server.go services.go types.go
Directories ¶
Path | Synopsis |
---|---|
cmd | |
cmd/protoc-gen-gogottrpc | |
cmd/protoc-gen-go-ttrpc | |
example | Package example demonstrates a lightweight protobuf service. |
example/cmd | |
plugin |
- Version
- v1.1.1
- Published
- Mar 24, 2023
- Platform
- js/wasm
- Imports
- 21 packages
- Last checked
- now –
Tools for package owners.