使用 viper 从 consul 读取配置文件

This commit is contained in:
2025-01-20 20:03:45 +08:00
parent ac288f01ca
commit 033579702f
3 changed files with 20 additions and 7 deletions
+3 -5
View File
@@ -1,11 +1,8 @@
package mysql
import (
"fmt"
"github.com/joho/godotenv"
"github.com/suyiiyii/hertz101/app/user/conf"
"os"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
@@ -20,8 +17,9 @@ func Init() {
if err != nil {
panic(err)
}
dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"), os.Getenv("MYSQL_PORT"))
DB, err = gorm.Open(mysql.Open(dsn),
//dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"), os.Getenv("MYSQL_PORT"))
//DB, err = gorm.Open(mysql.Open(dsn),
DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN),
&gorm.Config{
PrepareStmt: true,
SkipDefaultTransaction: true,