storage

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: MIT Imports: 15 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)

Register service implementor.

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   DialectType  `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) Meta

func (c *Config) Meta() *Config

func (*Config) Set

func (c *Config) Set(addr string)

func (*Config) Type

func (c *Config) Type() DialectType

type ConfigParams

type ConfigParams map[string]string

func (ConfigParams) Encode

func (cp ConfigParams) Encode(dialect DialectType) string

type Dialect

type Dialect interface {
	Type() DialectType
	Meta() *Config
	URL() string
}

func NewDialect

func NewDialect(cfg *Config) (Dialect, error)

func ParseDialect

func ParseDialect(addr string) (Dialect, error)

type DialectType

type DialectType string
const (
	DialectSQLite         DialectType = "sqlite3"
	DialectMySQL          DialectType = "mysql"
	DialectPostgreSQL     DialectType = "postgres"
	DialectMSSQL          DialectType = "mssql"
	DialectRedis          DialectType = "redis"
	DialectRedisCluster   DialectType = "rediscluster"
	DialectElasticSearch6 DialectType = "elasticsearch6"
	DialectElasticSearch7 DialectType = "elasticsearch7"
)

type ElasticOption

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

func WithElasticSearchMaxRetry

func WithElasticSearchMaxRetry(retries int) ElasticOption

type ElasticSearch

type ElasticSearch struct {
	*Config
}

func (*ElasticSearch) URL

func (d *ElasticSearch) URL() string

type MSSQL

type MSSQL struct {
	*Config
}

func (*MSSQL) URL

func (d *MSSQL) URL() string

type Manager

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

func Implementor

func Implementor() Manager

Return the service implementor.

type MySQL

type MySQL struct {
	*Config
}

func (*MySQL) URL

func (d *MySQL) URL() string

type PostgreSQL

type PostgreSQL struct {
	*Config
}

func (*PostgreSQL) URL

func (d *PostgreSQL) URL() string

type Redis

type Redis struct {
	*Config
}

func (*Redis) URL

func (d *Redis) URL() string

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 SQLOption

type SQLOption func(*gorm.DB)

func WithDBConnMaxLifetime

func WithDBConnMaxLifetime(dur time.Duration) SQLOption

func WithDBDump

func WithDBDump() SQLOption

func WithDBMaxIdleConn

func WithDBMaxIdleConn(maxIdleConn int) SQLOption

func WithDBMaxOpenConn

func WithDBMaxOpenConn(maxOpenConn int) SQLOption

type SQLite

type SQLite struct {
	*Config
}

func (*SQLite) URL

func (d *SQLite) URL() string

type Storage

type Storage interface {
	InitDB(configs []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