client

package
v0.0.0-...-f4159b9 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 9 Imported by: 11

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

View Source
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 New

func New(opts ...Option) (*Client, error)

New creates a client

func (*Client) Close

func (c *Client) Close() error

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.

func (*Client) Connect

func (c *Client) Connect() (err error)

Connect establishes the GRPC connection to the specified host.

type Option

type Option func(*options)

Option provides a function definition to set options

func WithCertPool

func WithCertPool(p *x509.CertPool) Option

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 WithDialopts

func WithDialopts(uc ...grpc.DialOption) Option

WithDialopts adds dial options.

func WithDisableTLS

func WithDisableTLS() Option

WithDisableTLS turns off tls.

func WithInsecureSkipVerify

func WithInsecureSkipVerify() Option

WithInsecureSkipVerify makes connections not that safe to use.

func WithLogger

func WithLogger(l log.Logger) Option

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 WithTarget

func WithTarget(t string) Option

WithTarget sets the target host.

func WithUnaryClientInterceptors

func WithUnaryClientInterceptors(uc ...grpc.UnaryClientInterceptor) Option

WithUnaryClientInterceptors sets the unary client middleware.

func WithViper

func WithViper(args ...string) Option

WithViper specifies that the client or server should construct its options using viper

Jump to

Keyboard shortcuts

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