storage

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: MIT Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithStorage

func ContextWithStorage(ctx context.Context) context.Context

func IsEmpty

func IsEmpty(err error) bool

func RegisterImplementor

func RegisterImplementor(mgr Manager)

RegisterImplementor registers the storage manage service implementor.

func RegisterSQLDialectImplementor added in v1.0.0

func RegisterSQLDialectImplementor(sql SQLDialect)

RegisterSQLDialectImplementor registers gorm sql Dialector.

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor for storage manager.

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor for storage manager.

Types

type Config

type Config struct {
	Schema   Schema       `json:"type"`
	Username string       `json:"username"`
	Password string       `json:"password"`
	Host     string       `json:"host"`
	Port     string       `json:"port"`
	Database string       `json:"database"`
	Params   ConfigParams `json:"params"`
}

func (*Config) Dialect added in v0.1.2

func (c *Config) Dialect() (Dialect, error)

func (*Config) Set

func (c *Config) Set(addr string)

type ConfigParams

type ConfigParams map[string]string

func (ConfigParams) Encode

func (cp ConfigParams) Encode(schema Schema) string

type Dialect

type Dialect interface {
	URL() string
}

type ElasticOption

type ElasticOption func(*es6.Config, *es7.Config)

func WithElasticSearchMaxRetry

func WithElasticSearchMaxRetry(retries int) ElasticOption

WithElasticSearchMaxRetry sets retry times.

func WithRetryOnTimeout added in v1.0.0

func WithRetryOnTimeout() ElasticOption

WithRetryOnTimeout enables retry on timeout.

func WithRetryStatus added in v1.0.0

func WithRetryStatus(status ...int) ElasticOption

WithRetryStatus sets status codes for retry. Default: 502, 503, 504.

func WithoutRetry added in v1.0.0

func WithoutRetry() ElasticOption

WithoutRetry disables retrying.

type Manager

type Manager interface {
	New(component string)
	Get(component string) Storage
}

func Implementor

func Implementor() Manager

Implementor returns the storage manage service implementor.

type RedisOption

type RedisOption func(*redis.Options)

func WithRedisIdleCheckFreq

func WithRedisIdleCheckFreq(dur time.Duration) RedisOption

func WithRedisMaxConnAge

func WithRedisMaxConnAge(dur time.Duration) RedisOption

func WithRedisMaxRetry

func WithRedisMaxRetry(retries int) RedisOption

type SQLDialect added in v1.0.0

type SQLDialect interface {
	Open(Config) gorm.Dialector
}

func SQLDialectImplementor added in v1.0.0

func SQLDialectImplementor() SQLDialect

SQLDialectImplementor returns the gorm sql Dialector implementor.

type SQLOption

type SQLOption func(*gorm.Config, *gorm.DB)

func WithDBConnMaxLifetime

func WithDBConnMaxLifetime(dur time.Duration) SQLOption

WithDBConnMaxLifetime sets the maximum amount of time a connection may be reused.

func WithDBDebug added in v1.0.0

func WithDBDebug() SQLOption

WithDBDebug starts debug mode.

func WithDBDryRun added in v1.0.0

func WithDBDryRun() SQLOption

WithDBDryRun generates sql without executing.

func WithDBMaxIdleConn

func WithDBMaxIdleConn(maxIdleConn int) SQLOption

WithDBMaxIdleConn sets the maximum number of connections in the idle connection pool.

func WithDBMaxOpenConn

func WithDBMaxOpenConn(maxOpenConn int) SQLOption

WithDBMaxOpenConn sets the maximum number of open connections to the database.

func WithoutDBAutomaticPing added in v1.0.0

func WithoutDBAutomaticPing() SQLOption

WithoutDBAutomaticPing disables automatic ping.

func WithoutDBDefaultTransaction added in v1.0.0

func WithoutDBDefaultTransaction() SQLOption

WithoutDBDefaultTransaction disables single create, update, delete operations in transaction.

type Schema added in v1.0.0

type Schema string
const (
	SQLite         Schema = "sqlite"
	MySQL          Schema = "mysql"
	PostgreSQL     Schema = "postgres"
	SQLServer      Schema = "sqlserver"
	Clickhouse     Schema = "clickhouse"
	Redis          Schema = "redis"
	RedisCluster   Schema = "rediscluster"
	ElasticSearch6 Schema = "elasticsearch6"
	ElasticSearch7 Schema = "elasticsearch7"
)

type Storage

type Storage interface {
	InitDB(master Config, slaves []Config, opts ...SQLOption) error
	InitElasticSearch(config Config, opts ...ElasticOption) error
	InitRedis(configs []Config, opts ...RedisOption) error
	GetDB(readOnly ...bool) *gorm.DB
	GetESv6() *es6.Client
	GetESv7() *es7.Client
	GetRedisz() []redis.Cmdable
	GetRedis(key interface{}) redis.Cmdable
}

Storage interface.

func ContextStorage

func ContextStorage(ctx context.Context, component string) Storage

Jump to

Keyboard shortcuts

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