增加注释

This commit is contained in:
linwenxiang committed 2020-10-29 14:48:25 +08:00
1 parent 22fb2b5d0b
commit 706c72b973
3 files changed
+8 -3

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
package database
// Setup 配置数据库
func Setup(driver string) {
dbType := driver
if dbType == "mysql" {
+1
View File
@@ -2,6 +2,7 @@ package database
import "gorm.io/gorm"
// Database 数据库配置
type Database interface {
Setup()
Open(conn string, cfg *gorm.Config) (db *gorm.DB, err error)
+6 -3
View File
@@ -5,12 +5,12 @@ import (
. "log"
"time"
goAdminLogger "github.com/go-admin-team/go-admin-core/logger"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
goAdminLogger "github.com/go-admin-team/go-admin-core/logger"
"go-admin/common/config"
"go-admin/common/global"
"go-admin/common/log"
@@ -18,9 +18,11 @@ import (
toolsConfig "go-admin/tools/config"
)
// Mysql mysql配置结构体
type Mysql struct {
}
// Setup 配置步骤
func (e *Mysql) Setup() {
global.Source = e.GetConnect()
log.Info(tools.Green(global.Source))
@@ -59,16 +61,17 @@ func (e *Mysql) Setup() {
}
}
// 打开数据库连接
// Open 打开数据库连接
func (e *Mysql) Open(db *sql.DB, cfg *gorm.Config) (*gorm.DB, error) {
return gorm.Open(mysql.New(mysql.Config{Conn: db}), cfg)
}
// 获取数据库连接
// GetConnect 获取数据库连接
func (e *Mysql) GetConnect() string {
return toolsConfig.DatabaseConfig.Source
}
// GetDriver 获取连接
func (e *Mysql) GetDriver() string {
return toolsConfig.DatabaseConfig.Driver
}