Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func InitGorm ¶
func InitGorm(c *MySQLConfig) (db *gorm.DB)
func InitRedis ¶
func InitRedis(c *RedisConfig) (rd *redis.Client)
func InitRedisCluster ¶
func InitRedisCluster(c *RedisConfig) (rc *redis.ClusterClient)
Types ¶
type MySQLConfig ¶
type MySQLConfig struct { DSN string `json:"dsn" toml:"dsn" yaml:"dsn"` // data source name. MaxOpenConn int `json:"max_open_conn" toml:"max_open_conn" yaml:"max_open_conn"` // pool, e.g:10 MaxIdleConn int `json:"max_idle_conn" toml:"max_idle_conn" yaml:"max_idle_conn"` // pool, e.g:100 MaxConnTimeout xtime.Duration `json:"max_conn_timeout" toml:"max_conn_timeout" yaml:"max_conn_timeout"` // connect max lifetime. Unmarshal config file e.g: 10s、2m、1m10s MaxIdleTimeout xtime.Duration `json:"max_idle_timeout" toml:"max_idle_timeout" yaml:"max_idle_timeout"` // connect max idle time. Unmarshal config file e.g: 10s、2m、1m10s LogLevel string `json:"log_level" toml:"log_level" yaml:"log_level"` // enum: info、warn、error、silent, default warn Colorful bool `json:"colorful" toml:"colorful" yaml:"colorful"` // is colorful log, default false SlowThreshold xtime.Duration `json:"slow_threshold" toml:"slow_threshold" yaml:"slow_threshold"` // slow sql log. Unmarshal config file e.g: 100ms、200ms、300ms、1s, default 200ms }
MySQLConfig mysql config.
type RedisConfig ¶
type RedisConfig struct { Addrs []string `json:"addrs" yaml:"addrs" toml:"addrs"` Username string `json:"username" yaml:"username" toml:"username"` Password string `json:"password" yaml:"password" toml:"password"` DB int `json:"db" yaml:"db" toml:"db"` ReadTimeout xtime.Duration `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"` WriteTimeout xtime.Duration `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"` PoolSize int `json:"pool_size" yaml:"pool_size" toml:"pool_size"` MinIdleConn int `json:"min_idle_conn" yaml:"min_idle_conn" toml:"min_idle_conn"` MaxIdleConn int `json:"max_idle_conn" yaml:"max_idle_conn" toml:"max_idle_conn"` TLS bool `json:"tls" yaml:"tls" toml:"tls"` TLSCfg *tls.Config `json:"-" yaml:"-" toml:"-"` Limiter redis.Limiter `json:"-" yaml:"-" toml:"-"` OnConnFunc func(ctx context.Context, cn *redis.Conn) error `json:"-" yaml:"-" toml:"-"` }
RedisConfig redis config.
Click to show internal directories.
Click to hide internal directories.