connect

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 16 Imported by: 3

README

go-connect

standard connector for 3rd party services. ex: redis, db, etc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureCircuitBreaker added in v1.2.0

func ConfigureCircuitBreaker(setting *CircuitSetting)

ConfigureCircuitBreaker is used to set the default value for any method hystrix will copy this value as the setting when setting for a command is not found

func NewGRPCConnection added in v1.3.0

func NewGRPCConnection(target string, poolSetting *GRPCConnectionPoolSetting, dialOptions ...grpc.DialOption) (*grpcpool.Pool, error)

NewGRPCConnection establish a new grpc connection (based on pool)

func NewGoRedisClusterConnectionPool

func NewGoRedisClusterConnectionPool(urls []string, opt *RedisConnectionPoolOptions) (*goredis.ClusterClient, error)

NewGoRedisClusterConnectionPool uses goredis library to establish the redis cluster connection pool

func NewGoRedisConnectionPool

func NewGoRedisConnectionPool(url string, opt *RedisConnectionPoolOptions) (*goredis.Client, error)

NewGoRedisConnectionPool uses goredis library to establish the redis connection pool

func NewHTTPConnection

func NewHTTPConnection(opt *HTTPConnectionOptions) *http.Client

NewHTTPConnection new http client

func NewRedigoRedisConnectionPool

func NewRedigoRedisConnectionPool(url string, opt *RedisConnectionPoolOptions) (*redigo.Pool, error)

NewRedigoRedisConnectionPool uses redigo library to establish the redis connection pool

func UnaryClientInterceptor added in v1.2.0

func UnaryClientInterceptor(opts *GRPCUnaryInterceptorOptions) grpc.UnaryClientInterceptor

UnaryClientInterceptor wrapper with circuit breaker, retry, timeout and metadata logging

Types

type CircuitSetting added in v1.2.0

type CircuitSetting struct {
	// Timeout is how long to wait for command to complete, in milliseconds
	Timeout int `json:"timeout"`

	// MaxConcurrentRequests is how many commands of the same type can run at the same time
	MaxConcurrentRequests int `json:"max_concurrent_requests"`

	// RequestVolumeThreshold is the minimum number of requests needed before a circuit can be tripped due to health
	RequestVolumeThreshold int `json:"request_volume_threshold"`

	// SleepWindow is how long, in milliseconds, to wait after a circuit opens before testing for recovery
	SleepWindow int `json:"sleep_window"`

	// ErrorPercentThreshold causes circuits to open once the rolling measure of errors exceeds this percent of requests
	ErrorPercentThreshold int `json:"error_percent_threshold"`
}

CircuitSetting is used to tune circuit settings at runtime

type GRPCConnectionPool added in v1.3.0

type GRPCConnectionPool struct {
	Conn *grpcpool.Pool
}

GRPCConnectionPool wrapper type for pooled grpc connection

type GRPCConnectionPoolSetting added in v1.3.0

type GRPCConnectionPoolSetting struct {
	MaxIdle         int
	MaxActive       int
	IdleTimeout     time.Duration
	MaxConnLifetime time.Duration
}

GRPCConnectionPoolSetting if set, then treat as pooled connection

type GRPCUnaryInterceptorOptions added in v1.2.0

type GRPCUnaryInterceptorOptions struct {
	// UseCircuitBreaker flag if the connection will implement a circuit breaker
	UseCircuitBreaker bool

	// RetryCount retry the operation if found error.
	// When set to <= 1, then it means no retry
	RetryCount int

	// RetryInterval next interval for retry.
	RetryInterval time.Duration

	// Timeout value, will return context deadline exceeded when the operation exceeds the duration
	Timeout time.Duration
}

GRPCUnaryInterceptorOptions wrapper options for the grpc connection

type HTTPConnectionOptions

type HTTPConnectionOptions struct {
	TLSHandshakeTimeout   time.Duration
	TLSInsecureSkipVerify bool
	Timeout               time.Duration
}

HTTPConnectionOptions options for the http connection

type RedisConnectionPoolOptions

type RedisConnectionPoolOptions struct {
	// Dial timeout for establishing new connections.
	// Default is 5 seconds. Only for go-redis.
	DialTimeout time.Duration

	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds. Only for go-redis.
	ReadTimeout time.Duration

	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout. Only for go-redis.
	WriteTimeout time.Duration

	// Number of idle connections in the pool.
	IdleCount int

	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	PoolSize int

	// Close connections after remaining idle for this duration. If the value
	// is zero, then idle connections are not closed. Applications should set
	// the timeout to a value less than the server's timeout.
	IdleTimeout time.Duration

	// Close connections older than this duration. If the value is zero, then
	// the pool does not close connections based on age.
	MaxConnLifetime time.Duration
}

RedisConnectionPoolOptions options for the redis connection

Jump to

Keyboard shortcuts

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