修改,兼容go-admin sdk方案

This commit is contained in:
linwenxiang committed 2021-03-09 19:12:49 +08:00
1 parent c541d09076
commit 25d8364bf4
151 files changed
+578 -3525

No files matched your search

+17 -17
View File
@@ -3,7 +3,8 @@ package api
import (
"context"
"fmt"
"go-admin/tools/app"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"log"
"net/http"
"os"
@@ -14,13 +15,12 @@ import (
"github.com/go-admin-team/go-admin-core/config/source/file"
"github.com/spf13/cobra"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
"go-admin/app/admin/router"
"go-admin/app/jobs"
"go-admin/common/database"
"go-admin/common/global"
"go-admin/pkg/logger"
"go-admin/tools"
"go-admin/tools/config"
)
var (
@@ -54,7 +54,7 @@ func setup() {
config.Setup(file.NewSource, file.WithPath(configYml))
go config.Watch()
//2. 设置日志
app.Runtime.SetLogger(
sdk.Runtime.SetLogger(
logger.SetupLogger(
config.LoggerConfig.Type,
config.LoggerConfig.Path,
@@ -70,10 +70,10 @@ func setup() {
func run() error {
defer config.Stop()
if config.ApplicationConfig.Mode == tools.ModeProd.String() {
if config.ApplicationConfig.Mode == pkg.ModeProd.String() {
gin.SetMode(gin.ReleaseMode)
}
engine := app.Runtime.GetEngine()
engine := sdk.Runtime.GetEngine()
if engine == nil {
engine = gin.New()
}
@@ -89,11 +89,11 @@ func run() error {
srv := &http.Server{
Addr: fmt.Sprintf("%s:%d", config.ApplicationConfig.Host, config.ApplicationConfig.Port),
Handler: app.Runtime.GetEngine(),
Handler: sdk.Runtime.GetEngine(),
}
go func() {
jobs.InitJob()
jobs.Setup(app.Runtime.GetDb())
jobs.Setup(sdk.Runtime.GetDb())
}()
@@ -112,20 +112,20 @@ func run() error {
}
}
}()
fmt.Println(tools.Red(string(global.LogoContent)))
fmt.Println(pkg.Red(string(global.LogoContent)))
tip()
fmt.Println(tools.Green("Server run at:"))
fmt.Println(pkg.Green("Server run at:"))
fmt.Printf("- Local: http://localhost:%d/ \r\n", config.ApplicationConfig.Port)
fmt.Printf("- Network: http://%s:%d/ \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
fmt.Println(tools.Green("Swagger run at:"))
fmt.Printf("- Network: http://%s:%d/ \r\n", pkg.GetLocaHonst(), config.ApplicationConfig.Port)
fmt.Println(pkg.Green("Swagger run at:"))
fmt.Printf("- Local: http://localhost:%d/swagger/index.html \r\n", config.ApplicationConfig.Port)
fmt.Printf("- Network: http://%s:%d/swagger/index.html \r\n", tools.GetLocaHonst(), config.ApplicationConfig.Port)
fmt.Printf("%s Enter Control + C Shutdown Server \r\n", tools.GetCurrentTimeStr())
fmt.Printf("- Network: http://%s:%d/swagger/index.html \r\n", pkg.GetLocaHonst(), config.ApplicationConfig.Port)
fmt.Printf("%s Enter Control + C Shutdown Server \r\n", pkg.GetCurrentTimeStr())
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
fmt.Printf("%s Shutdown Server ... \r\n", tools.GetCurrentTimeStr())
fmt.Printf("%s Shutdown Server ... \r\n", pkg.GetCurrentTimeStr())
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
@@ -136,6 +136,6 @@ func run() error {
}
func tip() {
usageStr := `欢迎使用 ` + tools.Green(`go-admin `+app.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
usageStr := `欢迎使用 ` + pkg.Green(`go-admin `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令`
fmt.Printf("%s \n\n", usageStr)
}
+4 -4
View File
@@ -3,7 +3,8 @@ package cmd
import (
"errors"
"fmt"
"go-admin/tools/app"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"go-admin/common/global"
"os"
"github.com/spf13/cobra"
@@ -12,7 +13,6 @@ import (
"go-admin/cmd/config"
"go-admin/cmd/migrate"
"go-admin/cmd/version"
"go-admin/tools"
)
var rootCmd = &cobra.Command{
@@ -23,7 +23,7 @@ var rootCmd = &cobra.Command{
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
tip()
return errors.New(tools.Red("requires at least one arg"))
return errors.New(pkg.Red("requires at least one arg"))
}
return nil
},
@@ -34,7 +34,7 @@ var rootCmd = &cobra.Command{
}
func tip() {
usageStr := `欢迎使用 ` + tools.Green(`go-admin `+app.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
usageStr := `欢迎使用 ` + pkg.Green(`go-admin `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令`
usageStr1 := `也可以参考 http://doc.zhangwj.com/go-admin-site/guide/ksks.html 里边的【启动】章节`
fmt.Printf("%s\n", usageStr)
fmt.Printf("%s\n", usageStr1)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/go-admin-team/go-admin-core/config/source/file"
"github.com/spf13/cobra"
"go-admin/tools/config"
"github.com/go-admin-team/go-admin-core/sdk/config"
)
var (
+12 -12
View File
@@ -6,18 +6,18 @@ import (
type DictData struct {
DictCode int `gorm:"primaryKey;autoIncrement;" json:"dictCode" example:"1"` //字典编码
DictSort int `gorm:"" json:"dictSort"` //显示顺序
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
CssClass string `gorm:"size:128;" json:"cssClass"` //
ListClass string `gorm:"size:128;" json:"listClass"` //
IsDefault string `gorm:"size:8;" json:"isDefault"` //
Status string `gorm:"size:4;" json:"status"` //状态
Default string `gorm:"size:8;" json:"default"` //
CreateBy string `gorm:"size:64;" json:"createBy"` //
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
Remark string `gorm:"size:255;" json:"remark"` //备注
DictSort int `gorm:"" json:"dictSort"` //显示顺序
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
DictType string `gorm:"size:64;" json:"dictType"` //字典类型
CssClass string `gorm:"size:128;" json:"cssClass"` //
ListClass string `gorm:"size:128;" json:"listClass"` //
IsDefault string `gorm:"size:8;" json:"isDefault"` //
Status string `gorm:"size:4;" json:"status"` //状态
Default string `gorm:"size:8;" json:"default"` //
CreateBy string `gorm:"size:64;" json:"createBy"` //
UpdateBy string `gorm:"size:64;" json:"updateBy"` //
Remark string `gorm:"size:255;" json:"remark"` //备注
models.BaseModel
}
+8 -8
View File
@@ -3,7 +3,8 @@ package migrate
import (
"bytes"
"fmt"
"go-admin/tools/app"
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"strconv"
"text/template"
"time"
@@ -11,14 +12,13 @@ import (
"github.com/go-admin-team/go-admin-core/config/source/file"
"github.com/spf13/cobra"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
"go-admin/cmd/migrate/migration"
_ "go-admin/cmd/migrate/migration/version"
_ "go-admin/cmd/migrate/migration/version-local"
"go-admin/common/database"
"go-admin/common/models"
"go-admin/pkg/logger"
"go-admin/tools"
"go-admin/tools/config"
)
var (
@@ -51,7 +51,7 @@ func run() {
//1. 读取配置
config.Setup(file.NewSource, file.WithPath(configYml))
//2. 设置日志
app.Runtime.SetLogger(
sdk.Runtime.SetLogger(
logger.SetupLogger(
config.LoggerConfig.Type,
config.LoggerConfig.Path,
@@ -68,7 +68,7 @@ func migrateModel() error {
if host == "" {
host = "*"
}
db := app.Runtime.GetDbByKey(host)
db := sdk.Runtime.GetDbByKey(host)
if config.DatabasesConfig[host].Driver == "mysql" {
//初始化数据库时候用
db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4")
@@ -105,9 +105,9 @@ func genFile() error {
var b1 bytes.Buffer
err = t1.Execute(&b1, m)
if goAdmin {
tools.FileCreate(b1, "./cmd/migrate/migration/version/"+m["GenerateTime"]+"_migrate.go")
pkg.FileCreate(b1, "./cmd/migrate/migration/version/"+m["GenerateTime"]+"_migrate.go")
} else {
tools.FileCreate(b1, "./cmd/migrate/migration/version-local/"+m["GenerateTime"]+"_migrate.go")
pkg.FileCreate(b1, "./cmd/migrate/migration/version-local/"+m["GenerateTime"]+"_migrate.go")
}
return nil
}
+2 -3
View File
@@ -2,9 +2,8 @@ package version
import (
"fmt"
"go-admin/tools/app"
"github.com/spf13/cobra"
"go-admin/common/global"
)
var (
@@ -22,6 +21,6 @@ var (
)
func run() error {
fmt.Println(app.Version)
fmt.Println(global.Version)
return nil
}