diff --git a/internal/pkg/db/db.go b/internal/pkg/db/db.go index 87919a4..4b67f2a 100644 --- a/internal/pkg/db/db.go +++ b/internal/pkg/db/db.go @@ -20,9 +20,6 @@ func InitDb() (*safety.Var[*sqlx.DB], error) { return nil, err } preDb := safeDb.Load() - if preDb != nil { - _ = preDb.Close() - } if c.Mysql.Pool.ConnMaxIdleTime != 0 { db.SetConnMaxIdleTime(c.Mysql.Pool.ConnMaxLifetime) } @@ -36,6 +33,9 @@ func InitDb() (*safety.Var[*sqlx.DB], error) { db.SetConnMaxLifetime(c.Mysql.Pool.ConnMaxLifetime) } safeDb.Store(db) + if preDb != nil { + _ = preDb.Close() + } return safeDb, err } diff --git a/internal/pkg/logs/log.go b/internal/pkg/logs/log.go index deffc18..3b08629 100644 --- a/internal/pkg/logs/log.go +++ b/internal/pkg/logs/log.go @@ -35,10 +35,10 @@ func InitLogger() error { out = file logFile.Store(file) } + logs.Store(l) if preFD != nil { _ = preFD.Close() } - logs.Store(l) l.SetFlags(log.Ldate | log.Ltime) l.SetOutput(out) return nil