refactor: update InitDB callers to use new parameterless signature

This commit is contained in:
Sora39831 2026-04-03 09:27:10 +08:00
parent 283892c548
commit 2647c2c2ce
3 changed files with 9 additions and 9 deletions

12
main.go
View file

@ -46,7 +46,7 @@ func runWebServer() {
godotenv.Load()
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
log.Fatalf("Error initializing database: %v", err)
}
@ -131,7 +131,7 @@ func runWebServer() {
// resetSetting resets all panel settings to their default values.
func resetSetting() {
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
fmt.Println("Failed to initialize database:", err)
return
@ -218,7 +218,7 @@ func updateTgbotEnableSts(status bool) {
// updateTgbotSetting updates Telegram bot settings including token, chat ID, and runtime schedule.
func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime string) {
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
fmt.Println("Error initializing database:", err)
return
@ -256,7 +256,7 @@ func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime stri
// updateSetting updates various panel settings including port, credentials, base path, listen IP, and two-factor authentication.
func updateSetting(port int, username string, password string, webBasePath string, listenIP string, resetTwoFactor bool) {
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
fmt.Println("Database initialization failed:", err)
return
@ -315,7 +315,7 @@ func updateSetting(port int, username string, password string, webBasePath strin
// updateCert updates the SSL certificate files for the panel.
func updateCert(publicKey string, privateKey string) {
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
fmt.Println(err)
return
@ -392,7 +392,7 @@ func GetListenIP(getListen bool) {
func migrateDb() {
inboundService := service.InboundService{}
err := database.InitDB(config.GetDBPath())
err := database.InitDB()
if err != nil {
log.Fatal(err)
}

View file

@ -1009,7 +1009,7 @@ func (s *ServerService) ImportDB(file multipart.File) error {
}
// Open & migrate new DB
if err = database.InitDB(config.GetDBPath()); err != nil {
if err = database.InitDBWithPath(config.GetDBPath()); err != nil {
if errRename := os.Rename(fallbackPath, config.GetDBPath()); errRename != nil {
return common.NewErrorf("Error migrating db and restoring fallback: %v", errRename)
}

View file

@ -16,7 +16,7 @@ func setupTestDB(t *testing.T) {
t.Setenv("XUI_DEBUG", "")
t.Setenv("XUI_DB_FOLDER", tmpDir)
dbPath := filepath.Join(tmpDir, "test.db")
if err := database.InitDB(dbPath); err != nil {
if err := database.InitDBWithPath(dbPath); err != nil {
t.Fatalf("InitDB failed: %v", err)
}
t.Cleanup(func() {
@ -120,7 +120,7 @@ func TestUpdateFirstUser_CreateWhenNone(t *testing.T) {
}()
dbPath := filepath.Join(tmpDir, "empty.db")
if err := database.InitDB(dbPath); err != nil {
if err := database.InitDBWithPath(dbPath); err != nil {
t.Fatalf("InitDB failed: %v", err)
}
defer database.CloseDB()