From 5b8d0ca3c0302f0b0d4067352595c549a3491757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=9C=E8=8F=AF?= Date: Sun, 14 May 2023 07:11:14 +0800 Subject: [PATCH] remove mysql --- configs/mysql.go | 38 -------------------------------------- configs/sqlite3.go | 10 ---------- go.mod | 4 ++-- go.sum | 2 -- 4 files changed, 2 insertions(+), 52 deletions(-) delete mode 100644 configs/mysql.go diff --git a/configs/mysql.go b/configs/mysql.go deleted file mode 100644 index 69b99bf..0000000 --- a/configs/mysql.go +++ /dev/null @@ -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) -} diff --git a/configs/sqlite3.go b/configs/sqlite3.go index 51e7fdb..35202f1 100644 --- a/configs/sqlite3.go +++ b/configs/sqlite3.go @@ -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{}) diff --git a/go.mod b/go.mod index 2911b1b..25b5b65 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,15 @@ module main go 1.18 require ( - github.com/go-sql-driver/mysql v1.7.1 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 - github.com/mattn/go-sqlite3 v1.14.16 github.com/russross/blackfriday v1.6.0 gorm.io/gorm v1.25.1 ) +require github.com/mattn/go-sqlite3 v1.14.16 // indirect + require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect diff --git a/go.sum b/go.sum index 7601b57..183c292 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= -github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=