client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package client define some utilities for dialing to target gRPC server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(address string, options ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a client connection to the given target with health check enabled and some others default configurations.

func DialContext

func DialContext(ctx context.Context, address string, options ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext creates a client connection to the given target with health check enabled and some others default configurations.

func DialOptionsFromConfig

func DialOptionsFromConfig(conf *Config) []grpc.DialOption

DialOptionsFromConfig return dial options from the given configuration.

func DialOptionsFromEnv

func DialOptionsFromEnv(opts ...config.ReadOption) []grpc.DialOption

DialOptionsFromEnv return dial options from environment variables.

func GetAddressFromEnv

func GetAddressFromEnv(opts ...config.ReadOption) string

GetAddressFromEnv returns address from configured environment variables: PORT or ADDRESS. This function prioritizes PORT over ADDRESS. If non of the variables is configured, return default address.

func Must

func Must(conn *grpc.ClientConn, err error) *grpc.ClientConn

Must return the given client connection if err is nil, otherwise panic.

func NewContext

func NewContext(ctx context.Context, kv ...string) context.Context

NewContext return new out going context with the given metadata, it also copies all associated metadata in the incoming/outcomming context to the new context. NewContext panics if len(kv) is odd.

func NewTracingContext

func NewTracingContext(ctx context.Context, correlationID string) context.Context

NewTracingContext return new context with the given correlation id for log tracing, it also copies all associated metadata in the incoming/outcoming context to the new context. If the given correlationID is empty, a new correlation id will be generated.

NOTE: that this function has nothing to do with tracing using opentracing.

func WithJWTCredentials

func WithJWTCredentials(token string) grpc.DialOption

WithJWTCredentials return a JWT credential dial option.

func WithStreamTracing

func WithStreamTracing(tracer opentracing.Tracer) grpc.DialOption

WithStreamTracing return stream tracing interceptor dial option.

func WithTLSTransportCredentials

func WithTLSTransportCredentials(certFile string) grpc.DialOption

WithTLSTransportCredentials return new dial option using TLS. panic if the given file is not found.

func WithTracing

func WithTracing(tracer opentracing.Tracer) grpc.DialOption

WithTracing return unary tracing interceptor dial option.

Types

type Config

type Config struct {
	// Address is the address of the server in form of host:port.
	// If PORT environment variable is configured, it will be prioritized over ADDRESS.
	Address     string `envconfig:"ADDRESS" default:"localhost:8000"`
	TLSCertFile string `envconfig:"TLS_CERT_FILE"`
	JWTToken    string `envconfig:"JWT_TOKEN"`
}

Config hold some basic client configuration.

func ReadConfigFromEnv

func ReadConfigFromEnv(opts ...config.ReadOption) *Config

ReadConfigFromEnv read client config from environment variables.

Jump to

Keyboard shortcuts

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