mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 18:26:16 +00:00
refactor: harden sqlite runtime and packaged startup flow
- refine config loading with --config and current-directory .env - improve sqlite busy handling and runtime DB tuning - restore telegram payment notification and wallet input flow - add behavior-based config and callback recovery tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/assimon/luuu/config"
|
||||
@@ -16,9 +17,10 @@ import (
|
||||
// SqliteInit 数据库初始化
|
||||
func SqliteInit() error {
|
||||
var err error
|
||||
dbFilename := "./conf/.db"
|
||||
if dbfile := viper.GetString("sqlite_database_filename"); len(dbfile) > 0 {
|
||||
dbFilename = filepath.Base(dbfile)
|
||||
dbFilename := config.GetPrimarySqlitePath()
|
||||
if err = os.MkdirAll(filepath.Dir(dbFilename), 0o755); err != nil {
|
||||
color.Red.Printf("[store_db] sqlite mkdir err=%s\n", err)
|
||||
return err
|
||||
}
|
||||
color.Green.Printf("[store_db] sqlite filename: %s\n", dbFilename)
|
||||
Mdb, err = openDB(dbFilename, &gorm.Config{
|
||||
@@ -33,22 +35,11 @@ func SqliteInit() error {
|
||||
// panic(err)
|
||||
return err
|
||||
}
|
||||
if config.AppDebug {
|
||||
if config.SQLDebug {
|
||||
Mdb = Mdb.Debug()
|
||||
}
|
||||
sqlDB, err := Mdb.DB()
|
||||
if err != nil {
|
||||
color.Red.Printf("[store_db] sqlite get DB,err=%s\n", err)
|
||||
// panic(err)
|
||||
return err
|
||||
}
|
||||
// sqlDB.SetMaxIdleConns(viper.GetInt("sqlite_max_idle_conns"))
|
||||
// sqlDB.SetMaxOpenConns(viper.GetInt("sqlite_max_open_conns"))
|
||||
// sqlDB.SetConnMaxLifetime(time.Hour * time.Duration(viper.GetInt("sqlite_max_life_time")))
|
||||
err = sqlDB.Ping()
|
||||
if err != nil {
|
||||
if _, err = configureSQLite(Mdb, 1); err != nil {
|
||||
color.Red.Printf("[store_db] sqlite connDB err:%s", err.Error())
|
||||
// panic(err)
|
||||
return err
|
||||
}
|
||||
log.Sugar.Debug("[store_db] sqlite connDB success")
|
||||
|
||||
Reference in New Issue
Block a user