175 lines
3.2 KiB
Go
175 lines
3.2 KiB
Go
package config
|
|
|
|
type redisConfig struct {
|
|
Addr string `json:"addr" yaml:"addr"`
|
|
Username string `json:"username" yaml:"username"`
|
|
Password string `json:"password" yaml:"password"`
|
|
DB int `json:"db" yaml:"db"`
|
|
Protocol int `json:"protocol" yaml:"protocol"`
|
|
DialTimeout int `json:"dialtimeout" yaml:"dialtimeout"`
|
|
ReadTimeout int `json:"readtimeout" yaml:"readtimeout"`
|
|
WriteTimeout int `json:"writetimeout" yaml:"writetimeout"`
|
|
PoolSize int `json:"poolsize" yaml:"poolsize"`
|
|
}
|
|
|
|
func NewRedisConfig() *redisConfig {
|
|
return new(redisConfig)
|
|
}
|
|
|
|
func (conf *redisConfig) GetAddr() string {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.Addr
|
|
}
|
|
|
|
func (conf *redisConfig) SetAddr(addr string) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.Addr = addr
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetUsername() string {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.Username
|
|
}
|
|
|
|
func (conf *redisConfig) SetUsername(username string) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.Username = username
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetPassword() string {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.Password
|
|
}
|
|
|
|
func (conf *redisConfig) SetPassword(password string) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.Password = password
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetDB() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.DB
|
|
}
|
|
|
|
func (conf *redisConfig) SetDB(db int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.DB = db
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetProtocol() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.Protocol
|
|
}
|
|
|
|
func (conf *redisConfig) SetProtocol(protocol int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.Protocol = protocol
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetDialTimeout() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.DialTimeout
|
|
}
|
|
|
|
func (conf *redisConfig) SetDialTimeout(dialTimeout int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.DialTimeout = dialTimeout
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetReadTimeout() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.ReadTimeout
|
|
}
|
|
|
|
func (conf *redisConfig) SetReadTimeout(readTimeout int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.ReadTimeout = readTimeout
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetWriteTimeout() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.WriteTimeout
|
|
}
|
|
|
|
func (conf *redisConfig) SetWriteTimeout(writeTimeout int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.WriteTimeout = writeTimeout
|
|
|
|
return conf
|
|
}
|
|
|
|
func (conf *redisConfig) GetPoolSize() int {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
|
|
return conf.PoolSize
|
|
}
|
|
|
|
func (conf *redisConfig) SetPoolSIze(poolSize int) *redisConfig {
|
|
if conf == nil {
|
|
panic("redis config is nil")
|
|
}
|
|
conf.PoolSize = poolSize
|
|
|
|
return conf
|
|
}
|
|
|
|
func redisConfigName() string {
|
|
return "redis.json"
|
|
}
|