feat: support configurable timezone
This commit is contained in:
parent
eb6f5d0aca
commit
dc50562f22
@ -21,6 +21,7 @@ Database:
|
||||
MaxOpenConns: ${DATABASE_MAX_OPEN_CONNS}
|
||||
MaxIdleConns: ${DATABASE_MAX_IDLE_CONNS}
|
||||
ConnMaxLifetime: ${DATABASE_CONN_MAX_LIFETIME}
|
||||
TimeZone: ${DATABASE_TIMEZONE}
|
||||
|
||||
Storage:
|
||||
Endpoint: ${STORAGE_ENDPOINT}
|
||||
|
@ -54,6 +54,7 @@ check_env "DATABASE_PREFIX" "oj_" true
|
||||
check_env "DATABASE_MAX_OPEN_CONNS" 100 false
|
||||
check_env "DATABASE_MAX_IDLE_CONNS" 60 false
|
||||
check_env "DATABASE_CONN_MAX_LIFETIME" 60 false
|
||||
check_env "DATABASE_TIMEZONE" "Asia/Shanghai" true
|
||||
|
||||
check_env "STORAGE_ENDPOINT" "minio:9000" true
|
||||
check_env "STORAGE_USE_SSL" "false" false
|
||||
|
@ -25,6 +25,7 @@ type ConfigDatabase struct {
|
||||
MaxOpenConns int `yaml:"MaxOpenConns"`
|
||||
MaxIdleConns int `yaml:"MaxIdleConns"`
|
||||
ConnMaxLifetime int `yaml:"ConnMaxLifetime"`
|
||||
TimeZone string `yaml:"TimeZone"`
|
||||
}
|
||||
|
||||
type ConfigStorage struct {
|
||||
|
@ -66,14 +66,15 @@ func (s *service) setup(conf *model.Config) {
|
||||
logger := zapgorm2.New(s.log)
|
||||
logger.IgnoreRecordNotFoundError = true
|
||||
|
||||
tz := utils.If(conf.Database.TimeZone == "", "Asia/Shanghai", conf.Database.TimeZone)
|
||||
dsn := fmt.Sprintf(
|
||||
// TODO: timezone as config
|
||||
"user=%s password=%s dbname=%s host=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
|
||||
"user=%s password=%s dbname=%s host=%s port=%d sslmode=disable TimeZone=%s",
|
||||
conf.Database.User,
|
||||
conf.Database.Password,
|
||||
conf.Database.Database,
|
||||
conf.Database.Host,
|
||||
conf.Database.Port,
|
||||
tz,
|
||||
)
|
||||
|
||||
s.db, s.err = gorm.Open(
|
||||
|
@ -54,7 +54,7 @@ func (s *service) HealthCheck() error {
|
||||
}
|
||||
|
||||
func (s *service) initRouters(conf *model.Config, injector *do.Injector) *gin.Engine {
|
||||
gin.SetMode(utils.If(conf.Development, gin.DebugMode, gin.ReleaseMode))
|
||||
gin.SetMode(utils.If[string](conf.Development, gin.DebugMode, gin.ReleaseMode))
|
||||
|
||||
r := gin.New()
|
||||
r.MaxMultipartMemory = 8 << 20
|
||||
|
Loading…
Reference in New Issue
Block a user