diff --git a/README.md b/README.md
index 6bf9b65d..35377ebc 100644
--- a/README.md
+++ b/README.md
@@ -90,6 +90,8 @@
[使用生成工具轻松实现业务](https://www.bilibili.com/video/BV1Dg4y1i79D)
+[v1.1.0版本代码生成工具-释放双手](https://www.bilibili.com/video/BV1N54y1i71P) [进阶]
+
[多命令启动方式讲解以及IDE配置](https://www.bilibili.com/video/BV1Fg4y1q7ph)
[go-admin菜单的配置说明](https://www.bilibili.com/video/BV1Wp4y1D715) [必看]
diff --git a/apis/tools/gen.go b/apis/tools/gen.go
index 24b962f4..87546c52 100644
--- a/apis/tools/gen.go
+++ b/apis/tools/gen.go
@@ -60,10 +60,10 @@ func GenCode(c *gin.Context) {
tab, _ := table.Get()
ischeckrole := true
- rouyerfile := "template/routercheckrole.go.template"
+ routerfile := "template/routercheckrole.go.template"
- if c.Param("ischeckrole") != "" {
- ischeckrole, err = tools2.StringToBool(c.Query("ischeckrole"))
+ if c.Request.FormValue("ischeckrole") != "" {
+ ischeckrole, err = tools2.StringToBool(c.Request.FormValue("ischeckrole"))
if err != nil {
ischeckrole = true
}
@@ -75,14 +75,14 @@ func GenCode(c *gin.Context) {
if !ischeckrole {
oldTest = "// {{无需认证路由自动补充在此处请勿删除}}"
newText = "// {{无需认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1)"
- rouyerfile = "template/routernocheckrole.go.template"
+ routerfile = "template/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/model.go.template")
tools2.HasError(err, "", -1)
t2, err := template.ParseFiles("template/api.go.template")
tools2.HasError(err, "", -1)
- t3, err := template.ParseFiles(rouyerfile)
+ t3, err := template.ParseFiles(routerfile)
tools2.HasError(err, "", -1)
t4, err := template.ParseFiles("template/js.go.template")
tools2.HasError(err, "", -1)
diff --git a/apis/tools/systables.go b/apis/tools/systables.go
index f28fe97a..b2e57ce6 100644
--- a/apis/tools/systables.go
+++ b/apis/tools/systables.go
@@ -168,8 +168,15 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables,
}
if strings.Contains(dbcolumn[i].ColumnType, "int") {
- column.GoType = "int"
+ if strings.Contains(dbcolumn[i].ColumnKey, "PR") {
+ column.GoType = "int"
+ } else {
+ column.GoType = "string"
+ }
column.HtmlType = "input"
+ } else if strings.Contains(dbcolumn[i].ColumnType, "timestamp") {
+ column.GoType = "time.Time"
+ column.HtmlType = "datetime"
} else {
column.GoType = "string"
column.HtmlType = "input"
diff --git a/cmd/api/server.go b/cmd/api/server.go
index bc37f865..fba0c8fa 100644
--- a/cmd/api/server.go
+++ b/cmd/api/server.go
@@ -25,9 +25,10 @@ var (
port string
mode string
StartCmd = &cobra.Command{
- Use: "server",
- Short: "Start API server",
- Example: "go-admin server config/settings.yml",
+ Use: "server",
+ Short: "Start API server",
+ Example: "go-admin server -c config/settings.yml",
+ SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
setup()
},
@@ -35,8 +36,11 @@ var (
return run()
},
}
+
+
)
+var echoTimes int
func init() {
StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on")
@@ -113,6 +117,6 @@ func run() error {
}
func tip() {
- usageStr := `欢迎使用 `+ tools.Green( `go-admin ` +global.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
+ usageStr := `欢迎使用 ` + tools.Green(`go-admin `+global.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
fmt.Printf("%s \n\n", usageStr)
}
diff --git a/cmd/cobra.go b/cmd/cobra.go
index 11a20835..6bf9808d 100644
--- a/cmd/cobra.go
+++ b/cmd/cobra.go
@@ -5,7 +5,9 @@ import (
"fmt"
"github.com/spf13/cobra"
"go-admin/cmd/api"
+ "go-admin/cmd/config"
"go-admin/cmd/migrate"
+ "go-admin/cmd/version"
"go-admin/global"
"go-admin/tools"
"os"
@@ -13,9 +15,8 @@ import (
var rootCmd = &cobra.Command{
Use: "go-admin",
- Short: "-v",
+ Short: "go-admin",
SilenceUsage: true,
- DisableAutoGenTag: true,
Long: `go-admin`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
@@ -40,6 +41,8 @@ func tip() {
func init() {
rootCmd.AddCommand(api.StartCmd)
rootCmd.AddCommand(migrate.StartCmd)
+ rootCmd.AddCommand(version.StartCmd)
+ rootCmd.AddCommand(config.StartCmd)
}
//Execute : apply commands
diff --git a/cmd/config/server.go b/cmd/config/server.go
new file mode 100644
index 00000000..c99a3d2c
--- /dev/null
+++ b/cmd/config/server.go
@@ -0,0 +1,61 @@
+package config
+
+import (
+ "encoding/json"
+ "fmt"
+ "go-admin/tools/config"
+
+ "github.com/spf13/cobra"
+)
+
+var (
+ configYml string
+ mode string
+ StartCmd = &cobra.Command{
+ Use: "config",
+ Short: "Get Application config info",
+ Example: "go-admin config -c config/settings.yml",
+ Run: func(cmd *cobra.Command, args []string) {
+ run()
+ },
+ }
+)
+
+func init() {
+ StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
+}
+
+func run() {
+ config.Setup(configYml)
+
+ application, errs := json.MarshalIndent(config.ApplicationConfig, "", " ") //转换成JSON返回的是byte[]
+ if errs != nil {
+ fmt.Println(errs.Error())
+ }
+ fmt.Println("application:", string(application))
+
+ jwt, errs := json.MarshalIndent(config.JwtConfig, "", " ") //转换成JSON返回的是byte[]
+ if errs != nil {
+ fmt.Println(errs.Error())
+ }
+ fmt.Println("jwt:", string(jwt))
+
+ database, errs := json.MarshalIndent(config.DatabaseConfig, "", " ") //转换成JSON返回的是byte[]
+ if errs != nil {
+ fmt.Println(errs.Error())
+ }
+ fmt.Println("database:", string(database))
+
+ gen, errs := json.MarshalIndent(config.GenConfig, "", " ") //转换成JSON返回的是byte[]
+ if errs != nil {
+ fmt.Println(errs.Error())
+ }
+ fmt.Println("gen:", string(gen))
+
+ loggerConfig, errs := json.MarshalIndent(config.LoggerConfig, "", " ") //转换成JSON返回的是byte[]
+ if errs != nil {
+ fmt.Println(errs.Error())
+ }
+ fmt.Println("logger:", string(loggerConfig))
+
+}
diff --git a/cmd/migrate/server.go b/cmd/migrate/server.go
index a7094ca7..dba76758 100644
--- a/cmd/migrate/server.go
+++ b/cmd/migrate/server.go
@@ -17,7 +17,8 @@ var (
mode string
StartCmd = &cobra.Command{
Use: "init",
- Short: "initialize the database",
+ Short: "Initialize the database",
+ Example: "go-admin init -c config/settings.yml",
Run: func(cmd *cobra.Command, args []string) {
run()
},
diff --git a/cmd/version/server.go b/cmd/version/server.go
new file mode 100644
index 00000000..2e959f66
--- /dev/null
+++ b/cmd/version/server.go
@@ -0,0 +1,30 @@
+package version
+
+import (
+ "fmt"
+ "github.com/spf13/cobra"
+ "go-admin/global"
+)
+
+var (
+ configYml string
+ port string
+ mode string
+ StartCmd = &cobra.Command{
+ Use: "version",
+ Short: "Get version info",
+ Example: "go-admin version",
+ PreRun: func(cmd *cobra.Command, args []string) {
+
+ },
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return run()
+ },
+ }
+)
+
+func run() error {
+ fmt.Println(global.Version)
+ return nil
+}
+
diff --git a/config/db.sql b/config/db.sql
index 95822107..711e19b0 100644
--- a/config/db.sql
+++ b/config/db.sql
@@ -267,7 +267,6 @@ INSERT INTO sys_dict_type VALUES (11, '1', '1', 1, '1', '1', '1', '2020-04-11 15
INSERT INTO `sys_menu` VALUES (2, 'Upms', '系统管理', 'example', '/upms', '/0/2', 'M', '无', '', 0, 1, '', 'Layout', 1, '0', '1', '1', '0', '2020-04-11 15:52:48', NULL, NULL);
INSERT INTO `sys_menu` VALUES (3, 'Sysuser', '用户管理', 'user', 'sysuser', '/0/2/3', 'C', '无', 'system:sysuser:list', 2, NULL, NULL, '/sysuser/index', 1, '0', '1', '1', '0', '2020-04-11 15:52:48', '2020-04-12 11:10:42', NULL);
-INSERT INTO `sys_menu` VALUES (4, 'GenCode', '新功能', 'example', '/gencode', '/0/4', 'M', '无', '', 0, 1, '', 'Layout', 1, '0', '1', '1', '0', '2020-04-11 15:52:48', NULL, NULL);
INSERT INTO `sys_menu` VALUES (43, NULL, '新增用户', NULL, '/api/v1/sysuser', '/0/2/3/43', 'F', 'POST', 'system:sysuser:add', 3, NULL, NULL, NULL, 0, '0', '1', '1', '0', '2020-04-11 15:52:48', NULL, NULL);
INSERT INTO `sys_menu` VALUES (44, NULL, '查询用户', NULL, '/api/v1/sysuser', '/0/2/3/44', 'F', 'GET', 'system:sysuser:query', 3, NULL, NULL, NULL, 0, '0', '1', '1', '0', '2020-04-11 15:52:48', NULL, NULL);
INSERT INTO `sys_menu` VALUES (45, NULL, '修改用户', NULL, '/api/v1/sysuser/', '/0/2/3/45', 'F', 'PUT', 'system:sysuser:edit', 3, NULL, NULL, NULL, 0, '0', '1', '1', '0', '2020-04-11 15:52:48', NULL, NULL);
diff --git a/config/settings.yml b/config/settings.yml
index 3cf120da..cce97534 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -20,7 +20,7 @@ settings:
# 日志等级
level: all
# 业务日志开关
- enabledbus: false
+ enabledbus: true
# 请求日志开关
enabledreq: false
# 数据库日志开关 dev模式,将自动开启
@@ -35,8 +35,6 @@ settings:
driver: mysql
# 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
- # source: sqlite3.db
- # source: host=myhost port=myport user=gorm dbname=gorm password=mypassword
gen:
# 代码生成读取的数据库名称
dbname: dbname
diff --git a/database/mysql-drive.go b/database/mysql-drive.go
index d007839f..5ef88ef6 100644
--- a/database/mysql-drive.go
+++ b/database/mysql-drive.go
@@ -20,13 +20,13 @@ func (e *Mysql) Setup() {
global.Logger.Info(tools.Green(global.Source))
global.Eloquent, err = db.Open(db.GetDriver(), db.GetConnect())
if err != nil {
- global.Logger.Error(tools.Red(db.GetDriver()+" connect error :"), err)
+ global.Logger.Fatal(tools.Red(db.GetDriver()+" connect error :"), err)
} else {
global.Logger.Info(tools.Green(db.GetDriver() + " connect success !"))
}
if global.Eloquent.Error != nil {
- global.Logger.Error(tools.Red(" database error :"), global.Eloquent.Error)
+ global.Logger.Fatal(tools.Red(" database error :"), global.Eloquent.Error)
}
global.Eloquent.LogMode(config.LoggerConfig.EnabledDB)
diff --git a/global/adm.go b/global/adm.go
index ce398930..b7192716 100644
--- a/global/adm.go
+++ b/global/adm.go
@@ -21,7 +21,7 @@ var (
var Version string
func init() {
- Version = "1.1.0"
+ Version = "1.1.1"
}
var (
diff --git a/middleware/customerror.go b/middleware/customerror.go
index 5fbd99d8..2dac7bc6 100644
--- a/middleware/customerror.go
+++ b/middleware/customerror.go
@@ -26,7 +26,7 @@ func CustomError(c *gin.Context) {
}
c.Status(statusCode)
fmt.Println(
- time.Now().Format("\n 2006-01-02 15:04:05.9999"),
+ time.Now().Format("2006-01-02 15:04:05.9999"),
"[ERROR]",
c.Request.Method,
c.Request.URL,
diff --git a/models/menu.go b/models/menu.go
index 4f436935..042014aa 100644
--- a/models/menu.go
+++ b/models/menu.go
@@ -9,7 +9,7 @@ import (
type Menu struct {
MenuId int `json:"menuId" gorm:"primary_key;AUTO_INCREMENT"`
MenuName string `json:"menuName" gorm:"size:128;"`
- Title string `json:"title" gorm:"size:64;"`
+ Title string `json:"title" gorm:"size:128;"`
Icon string `json:"icon" gorm:"size:128;"`
Path string `json:"path" gorm:"size:128;"`
Paths string `json:"paths" gorm:"size:128;"`
diff --git a/template/model.go.template b/template/model.go.template
index 92bffea2..682685cd 100644
--- a/template/model.go.template
+++ b/template/model.go.template
@@ -3,7 +3,10 @@ package models
import (
orm "go-admin/global"
"go-admin/tools"
-_ "time"
+{{$ii := 1}}
+{{ range .Columns }}
+ {{- if eq .GoType "time.Time" -}}{{- if eq $ii 1 -}} "time" {{$ii = 2}}{{- end}}{{- end}}
+{{- end }}
)
type {{.ClassName}} struct {
diff --git a/template/vue.go.template b/template/vue.go.template
index 305d1ad7..e19ee053 100644
--- a/template/vue.go.template
+++ b/template/vue.go.template
@@ -132,10 +132,14 @@
{{- else if eq "select" .HtmlType -}}
-
-
-
+
+
{{- else if eq "radio" .HtmlType -}}
@@ -145,6 +149,19 @@
:label="dict.dictValue"
>{{"{{"}} dict.dictLabel {{"}}"}}
+ {{- else if eq "datetime" .HtmlType -}}
+
+
+ {{- else if eq "textarea" .HtmlType -}}
+
+
{{- end }}
{{- end }}
diff --git a/tools/config/application.go b/tools/config/application.go
index c382de58..91f4ab44 100644
--- a/tools/config/application.go
+++ b/tools/config/application.go
@@ -19,7 +19,7 @@ func InitApplication(cfg *viper.Viper) *Application {
ReadTimeout: cfg.GetInt("readTimeout"),
WriterTimeout: cfg.GetInt("writerTimeout"),
Host: cfg.GetString("host"),
- Port: portDefault(cfg),
+ Port: cfg.GetString("port"),
Name: cfg.GetString("name"),
JwtSecret: cfg.GetString("jwtSecret"),
Mode: cfg.GetString("mode"),
@@ -28,13 +28,4 @@ func InitApplication(cfg *viper.Viper) *Application {
}
}
-var ApplicationConfig = new(Application)
-
-func portDefault(cfg *viper.Viper) string {
- if cfg.GetString("port") == "" {
- return "8000"
- } else {
- return cfg.GetString("port")
- }
-}
-
+var ApplicationConfig = new(Application)
\ No newline at end of file
diff --git a/tools/user.go b/tools/user.go
index 526ae38a..d3e0e841 100644
--- a/tools/user.go
+++ b/tools/user.go
@@ -3,7 +3,6 @@ package tools
import (
"fmt"
"github.com/gin-gonic/gin"
- "log"
jwt "go-admin/pkg/jwtauth"
)
@@ -21,7 +20,7 @@ func GetUserId(c *gin.Context) int {
if data["identity"] != nil {
return int((data["identity"]).(float64))
}
- log.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 说明:缺少identity")
+ fmt.Println(GetCurrentTimeStr()+" [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少identity")
return 0
}
@@ -30,7 +29,7 @@ func GetUserIdStr(c *gin.Context) string {
if data["identity"] != nil {
return Int64ToString(int64((data["identity"]).(float64)))
}
- log.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少identity")
+ fmt.Println(GetCurrentTimeStr()+" [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserIdStr 缺少identity")
return ""
}
@@ -39,7 +38,7 @@ func GetUserName(c *gin.Context) string {
if data["nice"] != nil {
return (data["nice"]).(string)
}
- fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少nice")
+ fmt.Println(GetCurrentTimeStr()+" [WARING] "+ c.Request.Method +" " + c.Request.URL.Path + " GetUserName 缺少nice")
return ""
}
@@ -48,7 +47,7 @@ func GetRoleName(c *gin.Context) string {
if data["rolekey"] != nil {
return (data["rolekey"]).(string)
}
- fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少rolekey")
+ fmt.Println(GetCurrentTimeStr()+" [WARING] "+ c.Request.Method +" " + c.Request.URL.Path + " GetRoleName 缺少rolekey")
return ""
}
@@ -58,6 +57,6 @@ func GetRoleId(c *gin.Context) int {
i := int((data["roleid"]).(float64))
return i
}
- fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少roleid")
+ fmt.Println(GetCurrentTimeStr()+" [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少roleid")
return 0
}