Understand gRPC-GO – part1- the components

the gRPC version: v1.0.1-GA

The who gRPC code base have several components

  • server
  • transport
  • clientconn
  • rpc_utils
  • metadata
  • credentials
  • codes
  • call


the server is mainly contain the gRPC server struct, service struct and main flow functions to handle grpc requests.

// Server is a gRPC server to serve RPC requests.
type Server struct {
	opts options

	mu    sync.Mutex // guards following
	lis   map[net.Listener]bool
	conns map[io.Closer]bool
	drain bool
	// A CondVar to let GracefulStop() blocks until all the pending RPCs are finished
	// and all the transport goes away.
	cv     *sync.Cond
	m      map[string]*service // service name -> service info
	events trace.EventLog


the transport package mainly contain the underlying communication mechanism(HTTP2 protocol) implementation and interface(ServerTransport, ClientTransport) for the server and client.


clientconn is mainly about connect and manage network connection to a gRPC server.


rpc_util mainly contains marshal, unmarshal, encode, receive, decode util function of rpc messages.


metadata package is about encode and decode metadata to and from context when sending or received grpc request.


credentials implements various credentials supported by gRPC library, which encapsulate all the state needed by a client to authenticate with a server and make various assertions.


define the error codes used by gRPC server


call.go contains the functions called by the IDL generated code(xxx.pb.go), which used to send grpc request and receive grpc response message.

Leave a Reply

Your email address will not be published. Required fields are marked *