connect

package module
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 47 Imported by: 1

README

go-connect

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CockroachDB represents gorm DB
	CockroachDB *gorm.DB
	// StopTickerCh signal for closing ticker channel
	StopTickerCh chan bool
)

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 InitTraceProvider added in v1.8.0

func InitTraceProvider(token, collectorURL, serviceName string, traceRatio float64) *sdktrace.TracerProvider

InitTraceProvider configures an OpenTelemetry exporter and trace provider

func InitializeCockroachConn added in v1.8.0

func InitializeCockroachConn(databaseDSN string, opt *CockroachDBConnectionOptions)

InitializeCockroachConn :nodoc:

func NewElasticsearchClient added in v1.8.0

func NewElasticsearchClient(url string, httpClient *http.Client, opt *ElasticsearchConnectionOptions) (*elastic.Client, error)

NewElasticsearchClient :nodoc:

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 NewUnaryGRPCConnection added in v1.7.0

func NewUnaryGRPCConnection(target string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, error)

NewUnaryGRPCConnection establish a new grpc connection

func RegisterHealthCheckService added in v1.15.0

func RegisterHealthCheckService(registrar grpc.ServiceRegistrar, customHandler grpc_health_v1.HealthServer)

RegisterHealthCheckService init health check service

func UnaryClientInterceptor added in v1.2.0

func UnaryClientInterceptor(opts *GRPCUnaryInterceptorOptions) grpc.UnaryClientInterceptor

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

func UnaryServerInterceptor added in v1.8.0

func UnaryServerInterceptor(opts *GRPCUnaryInterceptorOptions, redisClient *redis.Client) grpc.UnaryServerInterceptor

UnaryServerInterceptor wrapper with open telemetry

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 CockroachDBConnectionOptions added in v1.8.0

type CockroachDBConnectionOptions struct {
	PingInterval     time.Duration
	RetryAttempts    int
	MaxIdleConns     int
	MaxOpenConns     int
	ConnMaxLifetime  time.Duration
	LogLevel         string
	UseOpenTelemetry bool
}

CockroachDBConnectionOptions options for the CockroachDB connection

type ESErrorLogger added in v1.8.0

type ESErrorLogger struct{}

ESErrorLogger :nodoc:

func (*ESErrorLogger) Printf added in v1.8.0

func (*ESErrorLogger) Printf(format string, values ...interface{})

Printf :nodoc:

type ESInfoLogger added in v1.8.0

type ESInfoLogger struct{}

ESInfoLogger :nodoc:

func (*ESInfoLogger) Printf added in v1.8.0

func (*ESInfoLogger) Printf(format string, values ...interface{})

Printf :nodoc:

type ESTraceLogger added in v1.8.0

type ESTraceLogger struct{}

ESTraceLogger :nodoc:

func (*ESTraceLogger) Printf added in v1.8.0

func (*ESTraceLogger) Printf(format string, values ...interface{})

Printf :nodoc:

type ElasticsearchConnectionOptions added in v1.8.0

type ElasticsearchConnectionOptions struct {
	TLSHandshakeTimeout   time.Duration
	TLSInsecureSkipVerify bool
	MaxIdleConnections    int
	MaxConnsPerHost       int
	SetSniff              bool
	SetHealthcheck        bool
	UseOpenTelemetry      bool
}

ElasticsearchConnectionOptions options for the Elasticsearch connection

type GRPCRateLimiter added in v1.14.0

type GRPCRateLimiter struct {
	Limit              int64
	Period             time.Duration
	ExcludedIPs        []string
	ExcludedUserAgents []string
}

GRPCRateLimiter wrapper for the gRPC rate limiter

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

	// UseOpenTelemetry flag if the connection will implement open telemetry
	UseOpenTelemetry bool

	// RateLimiter flag if the connection will implement rate limiter
	RateLimiter *GRPCRateLimiter

	RecoveryHandlerFunc RecoveryHandlerFunc
}

GRPCUnaryInterceptorOptions wrapper options for the grpc connection

type GormCustomLogger added in v1.8.0

type GormCustomLogger struct {
	gormLogger.Config
}

GormCustomLogger override gorm logger

func NewGormCustomLogger added in v1.8.0

func NewGormCustomLogger() *GormCustomLogger

NewGormCustomLogger :nodoc:

func (*GormCustomLogger) Error added in v1.8.0

func (g *GormCustomLogger) Error(ctx context.Context, message string, values ...interface{})

Error :nodoc:

func (*GormCustomLogger) Info added in v1.8.0

func (g *GormCustomLogger) Info(ctx context.Context, message string, values ...interface{})

Info :nodoc:

func (*GormCustomLogger) LogMode added in v1.8.0

LogMode :nodoc:

func (*GormCustomLogger) Trace added in v1.8.0

func (g *GormCustomLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace :nodoc:

func (*GormCustomLogger) Warn added in v1.8.0

func (g *GormCustomLogger) Warn(ctx context.Context, message string, values ...interface{})

Warn :nodoc:

type HTTPConnectionOptions

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

HTTPConnectionOptions options for the http connection

type HealthCheckService added in v1.15.0

type HealthCheckService struct{}

HealthCheckService handler for health check rpc

func (HealthCheckService) Check added in v1.15.0

Check :nodoc:

func (HealthCheckService) Watch added in v1.15.0

Watch :nodoc:

type Option added in v1.8.0

type Option func(t *Transport)

Option signature for specifying options, e.g. WithRoundTripper.

func WithRoundTripper added in v1.8.0

func WithRoundTripper(rt http.RoundTripper) Option

WithRoundTripper specifies the http.RoundTripper to call next after this transport. If it is nil (default), the transport will use http.DefaultTransport.

type RecoveryHandlerFunc added in v1.13.0

type RecoveryHandlerFunc func(ctx context.Context, p interface{}) (err error)

RecoveryHandlerFunc is a function that recovers from the panic `p` by returning an `error`. The context can be used to extract request scoped metadata and context values.

type RedisConnectionPoolOptions

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

	// Enables read-only commands on slave nodes.
	ReadOnly bool

	// 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

type Transport added in v1.8.0

type Transport struct {
	// contains filtered or unexported fields
}

Transport for tracing HTTP operations.

func NewTransport added in v1.8.0

func NewTransport(opts ...Option) *Transport

NewTransport specifies a transport that will trace HTTP and report back via OpenTracing.

func (*Transport) RoundTrip added in v1.8.0

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip captures the request and starts an OpenTracing span for HTTP operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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