README
¶
Client
To quickly get a grpc connection (in this example, with non-system TLS certs) you'd simply do this:
Note: this example uses the grpc example protobufs
func getconn() echo.EchoClient {
cli, err := New(
WithCertPool(tls.LocalhostTLSConfig().RootCAs),
WithTarget("hostame:1234")
)
if err != nil {
log.Fatal(err)
}
err := cli.Connect(); err != nil {
log.Fatal(err)
}
return echo.NewEchoClient(cli.Conn())
}
This expects the following environment variables to be in place when calling WithViper() without arguments
Environment Variable | Description |
---|---|
DDL_RPC_TARGET | Sets the target host for an RPC client |
DDL_RPC_TLS_CERTIFICATE | Sets the client authentication cert for mutual tls |
DDL_RPC_KEY | Private key that pairs with tls certificate |
DDL_RPC_TLS_CA | Sets the certificate authority for client verification |
DDL_RPC_APP_KEY | populates the RPC context with an app key |
A full list of options can be found in options.go
Documentation
¶
Index ¶
- Constants
- type Client
- type Option
- func WithCertPool(p *x509.CertPool) Option
- func WithCertificate(c ...tls.Certificate) Option
- func WithClientAuth(a tls.ClientAuthType) Option
- func WithDialopts(uc ...grpc.DialOption) Option
- func WithDisableTLS() Option
- func WithInsecureSkipVerify() Option
- func WithLogger(l log.Logger) Option
- func WithStreamClientInterceptors(sc ...grpc.StreamClientInterceptor) Option
- func WithTarget(t string) Option
- func WithUnaryClientInterceptors(uc ...grpc.UnaryClientInterceptor) Option
- func WithViper(args ...string) Option
Constants ¶
const ( // EnvironmentPrefix sets the prefix to strip from environment variables when resolving keys. Default: "DDL_RPC". EnvironmentPrefix = "env-prefix" // EnvironmentReplace takes a comma separated list of old,new. Default: .,_,-,_ EnvironmentReplace = "env-replace" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an rpc connection
func (*Client) Close ¶
Close closes the connection. Calling close on an empty connection yells at you.
func (*Client) Conn ¶
func (c *Client) Conn() *grpc.ClientConn
Conn returns the connection established to the grpc host. This connection is concurrent safe and should be used when constructing grpc clients.
type Option ¶
type Option func(*options)
Option provides a function definition to set options
func WithCertPool ¶
WithCertPool overrides the system CA pool
func WithCertificate ¶
func WithCertificate(c ...tls.Certificate) Option
WithCertificate adds certs for authentication.
func WithClientAuth ¶
func WithClientAuth(a tls.ClientAuthType) Option
WithClientAuth sets the tls ClientAuthType to control auth behavior.
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify() Option
WithInsecureSkipVerify makes connections not that safe to use.
func WithLogger ¶
WithLogger set the log instance for client and server instances.
func WithStreamClientInterceptors ¶
func WithStreamClientInterceptors(sc ...grpc.StreamClientInterceptor) Option
WithStreamClientInterceptors sets the streaming client middleware.
func WithUnaryClientInterceptors ¶
func WithUnaryClientInterceptors(uc ...grpc.UnaryClientInterceptor) Option
WithUnaryClientInterceptors sets the unary client middleware.