package
0.13.0
Repository: https://github.com/go-kit/kit.git
Documentation: pkg.go.dev

# README

grpc

gRPC is an excellent, modern IDL and transport for microservices. If you're starting a greenfield project, go-kit strongly recommends gRPC as your default transport.

One important note is that while gRPC supports streaming requests and replies, go-kit does not. You can still use streams in your service, but their implementation will not be able to take advantage of many go-kit features like middleware.

Using gRPC and go-kit together is very simple.

First, define your service using protobuf3. This is explained in gRPC documentation. See addsvc.proto for an example. Make sure the proto definition matches your service's go-kit (interface) definition.

Next, get the protoc compiler.

You can download pre-compiled binaries from the protobuf release page. You will unzip a folder called protoc3 with a subdirectory bin containing an executable. Move that executable somewhere in your $PATH and you're good to go!

It can also be built from source.

brew install autoconf automake libtool
git clone https://github.com/google/protobuf
cd protobuf
./autogen.sh ; ./configure ; make ; make install

Then, compile your service definition, from .proto to .go.

protoc add.proto --go_out=plugins=grpc:.

Finally, write a tiny binding from your service definition to the gRPC definition. It's a simple conversion from one domain to another. See grpc.go for an example.

That's it! The gRPC binding can be bound to a listener and serve normal gRPC requests. And within your service, you can use standard go-kit components and idioms. See addsvc for a complete working example with gRPC support. And remember: go-kit services can support multiple transports simultaneously.

# Functions

ClientAfter sets the ClientResponseFuncs that are applied to the incoming gRPC response prior to it being decoded.
ClientBefore sets the RequestFuncs that are applied to the outgoing gRPC request before it's invoked.
ClientFinalizer is executed at the end of every gRPC request.
EncodeKeyValue sanitizes a key-value pair for use in gRPC metadata headers.
Interceptor is a grpc UnaryInterceptor that injects the method name into context so it can be consumed by Go kit gRPC middlewares.
NewClient constructs a usable Client for a single remote endpoint.
NewServer constructs a new server, which implements wraps the provided endpoint and implements the Handler interface.
ServerAfter functions are executed on the gRPC response writer after the endpoint is invoked, but before anything is written to the client.
ServerBefore functions are executed on the gRPC request object before the request is decoded.
ServerErrorHandler is used to handle non-terminal errors.
ServerErrorLogger is used to log non-terminal errors.
ServerFinalizer is executed at the end of every gRPC request.
SetRequestHeader returns a ClientRequestFunc that sets the specified metadata key-value pair.
SetResponseHeader returns a ResponseFunc that sets the specified metadata key-value pair.
SetResponseTrailer returns a ResponseFunc that sets the specified metadata key-value pair.

# Constants

# Structs

Client wraps a gRPC connection and provides a method that implements endpoint.Endpoint.
Server wraps an endpoint and implements grpc.Handler.

# Interfaces

Handler which should be called from the gRPC binding of the service implementation.

# Type aliases

ClientFinalizerFunc can be used to perform work at the end of a client gRPC request, after the response is returned.
ClientOption sets an optional parameter for clients.
ClientRequestFunc may take information from context and use it to construct metadata headers to be transported to the server.
ClientResponseFunc may take information from a gRPC metadata header and/or trailer and make the responses available for consumption.
DecodeRequestFunc extracts a user-domain request object from a gRPC request.
DecodeResponseFunc extracts a user-domain response object from a gRPC response object.
EncodeRequestFunc encodes the passed request object into the gRPC request object.
EncodeResponseFunc encodes the passed response object to the gRPC response message.
ServerFinalizerFunc can be used to perform work at the end of an gRPC request, after the response has been written to the client.
ServerOption sets an optional parameter for servers.
ServerRequestFunc may take information from the received metadata header and use it to place items in the request scoped context.
ServerResponseFunc may take information from a request context and use it to manipulate the gRPC response metadata headers and trailers.