remove mysql

This commit is contained in:
2023-05-14 07:11:14 +08:00
parent ee3b60eccc
commit 5b8d0ca3c0
4 changed files with 2 additions and 52 deletions

View File

@@ -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)
}

View File

@@ -4,7 +4,6 @@ import (
"log" "log"
"os" "os"
_ "github.com/mattn/go-sqlite3"
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "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 // ORMDB 使用 GORM
func ORMDB() (db *gorm.DB) { func ORMDB() (db *gorm.DB) {
db, err := gorm.Open(sqlite.Open("data/sqlite3.db"), &gorm.Config{}) db, err := gorm.Open(sqlite.Open("data/sqlite3.db"), &gorm.Config{})

4
go.mod
View File

@@ -3,15 +3,15 @@ module main
go 1.18 go 1.18
require ( require (
github.com/go-sql-driver/mysql v1.7.1
github.com/google/uuid v1.3.0 github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0 github.com/gorilla/websocket v1.5.0
github.com/mattn/go-sqlite3 v1.14.16
github.com/russross/blackfriday v1.6.0 github.com/russross/blackfriday v1.6.0
gorm.io/gorm v1.25.1 gorm.io/gorm v1.25.1
) )
require github.com/mattn/go-sqlite3 v1.14.16 // indirect
require ( require (
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect

2
go.sum
View File

@@ -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 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=