This commit is contained in:
2023-04-28 14:23:19 +08:00
parent d911d7eb87
commit bb58879595
8 changed files with 63 additions and 88 deletions

38
configs/mysql.go Normal file
View File

@@ -0,0 +1,38 @@
package configs
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"encoding/json"
"io/ioutil"
)
// 數據庫配置
type DBConfig struct {
Type string `json:"type"`
Host string `json:"host"`
Port int `json:"port"`
UserName string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
}
var conf DBConfig
func init() {
data, err := ioutil.ReadFile("./data/config.json")
if err != nil {
fmt.Println(err)
}
err = json.Unmarshal(data, &conf)
if err != nil {
fmt.Println(err)
}
}
func GetMySQL() (*sql.DB, error) {
return sql.Open(conf.Type, conf.UserName+":"+conf.Password+"@/"+conf.Database)
}

View File

@@ -52,6 +52,7 @@ func init() {
model_path TEXT,
status TEXT,
progress INTEGER,
image TEXT,
tags TEXT,
created_at TEXT,
updated_at TEXT,