remove mysql
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
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)
|
||||
}
|
@@ -4,7 +4,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -19,15 +18,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
//// GetDB 獲取數據庫連接
|
||||
//func GetDB() (*sql.DB, error) {
|
||||
// db, err := sql.Open("sqlite3", "data/sqlite3.db")
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return db, nil
|
||||
//}
|
||||
|
||||
// ORMDB 使用 GORM
|
||||
func ORMDB() (db *gorm.DB) {
|
||||
db, err := gorm.Open(sqlite.Open("data/sqlite3.db"), &gorm.Config{})
|
||||
|
Reference in New Issue
Block a user