# README
gRPCx
This package provides a simple set of utilities for common use cases when working with gRPC protocol and protocol buffers.
Installation
go get github.com/tangelo-labs/go-grpcx
Usage
Dialing a gRPC backend using a configuration string:
package main
import (
"context"
"github.com/tangelo-labs/go-grpcx"
)
func main() {
ctx := context.Background()
conn, err := grpcx.ParseClientConfigDial(ctx, `grpc://example.com:443?tls=true&blocking=true&timeout=10s`)
if err != nil {
panic(err)
}
// use conn to build a gRPC client.
}
See client.go
and related tests for more examples and available options.
# Packages
No description provided by the author
# Functions
ContentTypeProtoHeader computes the corresponding value for the "content-type" HTTP header for the given proto message.
NewBalancer creates a new Balancer instance.
NewBaseErrorMapper same as NewErrorMapper but creates a new instances that has two pre-registered rules:
- context.Canceled to codes.Canceled - context.DeadlineExceeded to codes.DeadlineExceeded.
NewClientConnPool returns a new instance of ClientConn that uses a pool of grpc.ClientConn instances when calling Invoke and NewStream using a round-robin strategy.
NewErrorMapper creates a new ErrorMapper with the given default code.
ParseClientConfig parses a ClientConfig from a string.
ParseClientConfigDial convenience function that parses a ClientConfig from a string and returns a clean gRPC connection.
ParseClientConfigDialPool same as ParseClientConfigDial but returns a connection pool instead.
ParseHostAndPort parses a host and port from a string given in the format: `host:port`.
ServerStreamWithContext decorates the given ServerStream with provided context.
UnmarshalHTTPRequest assumes that the given request has a body that is a protobuf message, and unmarshal it into a proto.Message of the type defined by the Request's header `content-type`.
UnmarshalHTTPResponse same as UnmarshalHTTPRequest, but for HTTP responses.
WriteGinResponse writes the given proto.Message as the response body of the given gin.Context, using the given HTTP status code.
# Variables
ErrInvalidClientConnectionString raised when failing to parse a connection string using the ParseClientConfig function.
# Structs
Balancer is a generic and thread-safe round-robin balancer.
ClientConfig captures the configuration details for a gRPC client connection.
Dialer is used to control the dialing process of a gRPC backend connection.
ErrorMapper is a utility to map Go errors to gRPC status codes.
# Interfaces
ClientConn is an abstraction for grpc.ClientConn.