Add: base config

main
git 2023-04-09 23:14:24 +08:00
parent 9e599b4192
commit 9670965242
Signed by: git
GPG Key ID: 3F65EFFA44207ADD
3 changed files with 85 additions and 0 deletions

35
config/base.go Normal file
View File

@ -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
}

22
config/logging.go Normal file
View File

@ -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
}

28
config/redis.go Normal file
View File

@ -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
}