diff --git a/config/base.go b/config/base.go new file mode 100644 index 0000000..230f50d --- /dev/null +++ b/config/base.go @@ -0,0 +1,35 @@ +package config + +import ( + "time" +) + +const ( + // DevEnv + DevEnv = "dev" + // ProdEnv + ProdEnv = "prod" +) + +// BaseConf +type BaseConf struct { + AppCode string `yaml:"app_code"` + AppSecret string `yaml:"app_secret"` + TimeZone string `yaml:"time_zone"` + LanguageCode string `yaml:"language_code"` + RunEnv string `yaml:"run_env"` + Location *time.Location `yaml:"-"` +} + +// Init +func (c *BaseConf) Init() error { + var err error + c.TimeZone = "Asia/Shanghai" + c.LanguageCode = "en-us" + c.RunEnv = DevEnv + c.Location, err = time.LoadLocation(c.TimeZone) + if err != nil { + return err + } + return nil +} diff --git a/config/logging.go b/config/logging.go new file mode 100644 index 0000000..d390149 --- /dev/null +++ b/config/logging.go @@ -0,0 +1,22 @@ +package config + +// LogConf : config for logging +type LogConf struct { + Level string `yaml:"level"` + File string `yaml:"file"` + Stderr bool `yaml:"stderr"` + CmdFile string `yaml:"-"` + CmdLevel string `yaml:"-"` +} + +// Init : init default logging config +func (c *LogConf) Init() error { + // only for development + c.Level = "info" + c.File = "" + c.Stderr = true + c.CmdFile = "" + c.CmdLevel = "info" + + return nil +} diff --git a/config/redis.go b/config/redis.go new file mode 100644 index 0000000..d4fac52 --- /dev/null +++ b/config/redis.go @@ -0,0 +1,28 @@ +package config + +type RedisConf struct { + Host string `yaml:"host"` + Port int `yaml:"port"` + Password string `yaml:"password"` + DB int `yaml:"db"` + MaxPoolSize int `yaml:"max_pool_size"` + MaxConnTimeout int `yaml:"max_conn_timeout"` + IdleTimeout int `yaml:"idle_timeout"` + ReadTimeout int `yaml:"read_timeout"` + WriteTimeout int `yaml:"write_timeout"` +} + +func (c *RedisConf) Init() error { + // only for development + c.Host = "127.0.0.1" + c.Port = 6379 + c.Password = "" + c.DB = 0 + + c.MaxPoolSize = 100 + c.MaxConnTimeout = 6 + c.IdleTimeout = 600 + c.ReadTimeout = 10 + c.WriteTimeout = 10 + return nil +}