grpc

package
v0.10.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 21 Imported by: 1

Documentation

Overview

Package grpc implements gRPC clients. Package grpc also contains implementations for gRPC-Web and gRPC reflection.

Index

Constants

This section is empty.

Variables

View Source
var ErrMutualAuthParamsAreNotEnough = errors.New("cert and certkey are required to authenticate mutually")

Functions

This section is empty.

Types

type BidiStream

type BidiStream interface {
	// Header returns the response header.
	Header() (metadata.MD, error)
	// Trailer returns the response trailer.
	Trailer() metadata.MD
	Send(req interface{}) error
	Receive(res interface{}) error
	CloseSend() error
}

type Client

type Client interface {
	// Invoke invokes a request req to the gRPC server. Then, Invoke decodes the response to res.
	Invoke(ctx context.Context, fqrn string, req, res interface{}) (header, trailer metadata.MD, _ error)

	// NewClientStream creates a new client stream.
	NewClientStream(ctx context.Context, streamDesc *grpc.StreamDesc, fqrn string) (ClientStream, error)

	// NewServerStream creates a new server stream.
	NewServerStream(ctx context.Context, streamDesc *grpc.StreamDesc, fqrn string) (ServerStream, error)

	// NewBidiStream creates a new bidirectional stream.
	NewBidiStream(ctx context.Context, streamDesc *grpc.StreamDesc, fqrn string) (BidiStream, error)

	// Close closes all connections the client has.
	Close(ctx context.Context) error

	// Header returns all request headers (metadata) Client has.
	Header() Headers

	grpcreflection.Client
}

Client represents the gRPC client.

func NewClient

func NewClient(addr, serverName string, useReflection, useTLS bool, cacert, cert, certKey string, headers map[string][]string) (Client, error)

NewClient creates a new gRPC client. It dials to the server specified by addr. addr format is the same as the first argument of grpc.Dial. If serverName is not empty, it overrides the gRPC server name used to verify the hostname on the returned certificates. If useReflection is true, the gRPC client enables gRPC reflection. If useTLS is true, the gRPC client establishes a secure connection with the server.

The set of cert and certKey enables mutual authentication if useTLS is enabled. If one of it is not found, NewClient returns ErrMutualAuthParamsAreNotEnough. If useTLS is false, cacert, cert and certKey are ignored.

func NewWebClient

func NewWebClient(addr string, useReflection, useTLS bool, cacert, cert, certKey string, headers Headers) Client

type ClientStream

type ClientStream interface {
	// Header returns the response header.
	Header() (metadata.MD, error)
	// Trailer returns the response trailer.
	Trailer() metadata.MD
	Send(req interface{}) error
	CloseAndReceive(res interface{}) error
}

type Headers

type Headers map[string][]string

Headers represents gRPC headers. A key corresponds to one or more values.

func (Headers) Add

func (h Headers) Add(k, v string) error

Add appends a value v to a key k. k must be consisted of other than '-', '_' and '.'.

func (Headers) Remove

func (h Headers) Remove(k string)

Remove deletes values corresponds to a key k.

type RPC

type RPC struct {
	Name               string
	FullyQualifiedName string
	RequestType        *Type
	ResponseType       *Type
	IsServerStreaming  bool
	IsClientStreaming  bool
}

RPC represents a RPC which belongs to a gRPC service.

type ServerStream

type ServerStream interface {
	// Header returns the response header.
	Header() (metadata.MD, error)
	// Trailer returns the response trailer.
	Trailer() metadata.MD
	Send(req interface{}) error
	Receive(res interface{}) error
}

type Type

type Type struct {
	// Name is the name of Type.
	Name string

	// FullyQualifiedName is the name that contains the package name this Type belongs.
	FullyQualifiedName string

	// New instantiates a new instance of Type.  It is used for decode requests and responses.
	New func() interface{}
}

Type is a type for representing requests/responses.

Directories

Path Synopsis
Package grpcreflection provides gRPC reflection client.
Package grpcreflection provides gRPC reflection client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL