Documentation ¶
Index ¶
- Variables
- func ToEndpoint(pkg string, s *descriptor.ServiceDescriptorProto, ...) string
- type BidiStreamClient
- type Client
- func (c *Client) BidiStreaming(ctx context.Context, req *Request) (BidiStreamClient, error)
- func (c *Client) ClientStreaming(ctx context.Context) (ClientStreamClient, error)
- func (c *Client) ServerStreaming(ctx context.Context, req *Request) (ServerStreamClient, error)
- func (c *Client) Unary(ctx context.Context, req *Request) (*Response, error)
- type ClientOption
- type ClientStreamClient
- type HTTPTransport
- type Request
- type Response
- type ServerStreamClient
- type StreamTransport
- type StreamTransportBuilder
- type Transport
- type TransportBuilder
- type WebSocketTransport
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTransportBuilder TransportBuilder = HTTPTransportBuilder DefaultStreamTransportBuilder StreamTransportBuilder = WebSocketTransportBuilder )
var (
ErrConnectionClosed = errors.New("connection closed")
)
Functions ¶
func ToEndpoint ¶
func ToEndpoint(pkg string, s *descriptor.ServiceDescriptorProto, m *descriptor.MethodDescriptorProto) string
ToEndpoint generates an endpoint from a service descriptor and a method descriptor.
Types ¶
type BidiStreamClient ¶
BidiStreamClient sends multi requests and receives multi responses. At the end, BidiStreamClient must be call Close method.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client starts each API session.
func NewClient ¶
func NewClient(host string, opts ...ClientOption) *Client
NewClient instantiates new API client for a gRPC Web API server. Client accepts some options to configure transports, codec, and so on. The default codec is Protocol Buffers.
func (*Client) BidiStreaming ¶
BidiStreamClient instantiates bidirectional streaming client.
func (*Client) ClientStreaming ¶
func (c *Client) ClientStreaming(ctx context.Context) (ClientStreamClient, error)
ClientStreamClient sends multi requests and receives only one response.
func (*Client) ServerStreaming ¶
ServerStreamClient sends only one request and receives multi responses through a stream.
type ClientOption ¶
type ClientOption func(*Client)
func WithCodec ¶
func WithCodec(codec encoding.Codec) ClientOption
func WithStreamTransportBuilder ¶
func WithStreamTransportBuilder(b StreamTransportBuilder) ClientOption
func WithTransportBuilder ¶
func WithTransportBuilder(b TransportBuilder) ClientOption
type ClientStreamClient ¶
ClientStreamClient sends multi requests and receives only one response. At the end, ClientStreamClient must be call CloseAndReceive method.
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
func (*HTTPTransport) Send ¶
func (t *HTTPTransport) Send(ctx context.Context, body io.Reader) (io.ReadCloser, error)
type Response ¶
type Response struct { ContentType string Content interface{} }
Response contains ContentType and its Content. ContentType is same as the value of Name() of encoding.Codec. Actual type of Content is depends on ContentType. For example, proto.Message if ContentType is "proto".
type ServerStreamClient ¶
type StreamTransport ¶
type StreamTransport interface { Send(body io.Reader) error Receive() (io.ReadCloser, error) // Finish sends EOF request to the server. Finish() (io.ReadCloser, error) // Close closes the connection. Close() error }
StreamTransport is used to send API requests for ClientStreamClient and BidiStreamClient.
func WebSocketTransportBuilder ¶
func WebSocketTransportBuilder(host string, endpoint string) (StreamTransport, error)
type StreamTransportBuilder ¶
type StreamTransportBuilder func(host string, endpoint string) (StreamTransport, error)
type Transport ¶
Transport creates new request. Transport is created only one per one request, MUST not use used transport again.
func HTTPTransportBuilder ¶
type TransportBuilder ¶
type WebSocketTransport ¶
type WebSocketTransport struct {
// contains filtered or unexported fields
}
WebSocketTransport is a stream transport implementation.
Currently, gRPC Web specification does not support client streaming. (https://github.com/improbable-eng/grpc-web#client-side-streaming) WebSocketTransport supports improbable-eng/grpc-web's own implementation.
spec: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md
func (*WebSocketTransport) Close ¶
func (t *WebSocketTransport) Close() error
func (*WebSocketTransport) Finish ¶
func (t *WebSocketTransport) Finish() (io.ReadCloser, error)
func (*WebSocketTransport) Receive ¶
func (t *WebSocketTransport) Receive() (res io.ReadCloser, err error)