[agent-go] 开始使用GO重构Agent部分
This commit is contained in:
27
server-go/service/DBConfig.go
Normal file
27
server-go/service/DBConfig.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"server-go/entity"
|
||||
)
|
||||
|
||||
func InitDB() *gorm.DB {
|
||||
|
||||
// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
|
||||
dsn := "wmm:Superwmm.23@tcp(42.192.52.227:21306)/gormdb?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// init the table
|
||||
db.AutoMigrate(&entity.ServerInfo{})
|
||||
|
||||
// cache this db to global
|
||||
entity.CONGIG.DB = db
|
||||
|
||||
return db
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user