Compare commits

...
20 Commits
Author SHA1 Message Date
wenjianzhang 055a68de7f Merge pull request #183 from wenjianzhang/dev
fix: Use NewSyncedEnforcer instead NewEnforcer to solve the thread safe
2020-08-03 14:25:59 +08:00
wenjianzhang 40492e56a0 ver : update version 1.1.2 2020-08-03 14:23:47 +08:00
wenjianzhang e51b72d2e4 Merge pull request #182 from nodece/patch-1
fix: Use NewSyncedEnforcer instead NewEnforcer
2020-08-03 14:16:33 +08:00
Zixuan Liu cb9ae9b8ec fix: Use NewSyncedEnforcer instead NewEnforcer to solve the thread safe
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
2020-08-03 14:12:07 +08:00
wenjianzhang 3316433f13 Merge pull request #178 from wenjianzhang/dev
1. 代码生成添加操作按钮确认提示;
2. 代码生成添加时间类型支持;
3. 代码生成添加时间控件、下拉控件、文本域的支持;
4. 修复代码生成无需权限的问题;
5. 修改了部分格式问题;
6. 默认开启log;
7. 修复了已知bug;
2020-08-01 14:52:29 +08:00
zhangwenjian c98f38cab4 gen :update import 2020-08-01 14:43:38 +08:00
zhangwenjian 88a458a003 gen : remove value-format 2020-08-01 14:07:06 +08:00
zhangwenjian 89fe63c915 gen : upgrade gen 2020-08-01 12:56:19 +08:00
zhangwenjian 80ef9e46ab Merge branch 'dev' of https://github.com/wenjianzhang/go-admin into dev 2020-08-01 11:11:44 +08:00
zhangwenjian 259b77dc08 fix : fix no auth code gen router 2020-08-01 11:08:40 +08:00
zhangwenjian 55b055b9a0 version : update version 2020-08-01 11:00:36 +08:00
zhangwenjian 309be41b05 feat : added version & config 2020-08-01 11:00:06 +08:00
zhangwenjian 1a580366fc feat : enabledbus status to true 2020-08-01 10:52:49 +08:00
zhangwenjian 93ac874312 feat : logger type error to fatal 2020-08-01 10:52:17 +08:00
zhangwenjian e5d22c78c8 doc : update readme 2020-08-01 10:50:19 +08:00
zhangwenjian 8d7a6ef3bb feat : update log format 2020-08-01 10:49:36 +08:00
zhangwenjian f050924234 sql : remove no used sql 2020-07-29 23:32:34 +08:00
zhangwenjian 061cb61aa7 remove : Prot default value removal 2020-07-29 23:31:51 +08:00
zhangwenjian 59e966ede6 feat : Adjust the length of the title field from the original 64 to 128 2020-07-29 15:08:44 +08:00
wenjianzhang 697ec9fcd5 doc : update readme 2020-07-28 00:07:41 +08:00
19 changed files with 163 additions and 47 deletions
+3
View File
@@ -24,6 +24,7 @@
系统初始化极度简单,只需要配置文件中,修改数据库连接,系统启动后会自动初始化数据库信息以及必须的基础数据
[在线文档国际](https://wenjianzhang.github.io/go-admin-site)
[在线文档国内](http://mydearzwj.gitee.io/go-admin-site/)
[前端项目](https://github.com/wenjianzhang/go-admin-ui)
@@ -89,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) [必看]
+5 -5
View File
@@ -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)
+8 -1
View File
@@ -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"
+8 -4
View File
@@ -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)
}
+5 -2
View File
@@ -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
+61
View File
@@ -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))
}
+2 -1
View File
@@ -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()
},
+30
View File
@@ -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
}
-1
View File
@@ -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);
+1 -3
View File
@@ -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
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -8,7 +8,7 @@ import (
)
var GinEngine *gin.Engine
var CasbinEnforcer *casbin.Enforcer
var CasbinEnforcer *casbin.SyncedEnforcer
var Eloquent *gorm.DB
var (
@@ -21,7 +21,7 @@ var (
var Version string
func init() {
Version = "1.1.0"
Version = "1.1.2"
}
var (
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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;"`
+2 -2
View File
@@ -33,14 +33,14 @@ func Setup() {
if err != nil {
panic(err)
}
e, err := casbin.NewEnforcer(m, Apter)
e, err := casbin.NewSyncedEnforcer(m, Apter)
if err != nil {
panic(err)
}
global.CasbinEnforcer = e
}
func Casbin() (*casbin.Enforcer, error) {
func Casbin() (*casbin.SyncedEnforcer, error) {
if err := global.CasbinEnforcer.LoadPolicy(); err == nil {
return global.CasbinEnforcer, err
} else {
+4 -1
View File
@@ -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 {
+21 -4
View File
@@ -132,10 +132,14 @@
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
{{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
{{- else if eq "select" .HtmlType -}}
<el-select
v-model="form.{{.JsonField}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
<el-option label="demo1" value="demo1"/>
<el-option label="demo2" value="demo2"/>
<el-select v-model="form.{{.JsonField}}"
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
<el-option
v-for="dict in {{.JsonField}}Options"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
{{- else if eq "radio" .HtmlType -}}
<el-radio-group v-model="form.{{.JsonField}}">
@@ -145,6 +149,19 @@
:label="dict.dictValue"
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
</el-radio-group>
{{- else if eq "datetime" .HtmlType -}}
<el-date-picker
v-model="form.{{.JsonField}}"
type="datetime"
placeholder="选择日期">
</el-date-picker>
{{- else if eq "textarea" .HtmlType -}}
<el-input
v-model="form.{{.JsonField}}"
type="textarea"
:rows="2"
placeholder="请输入内容">
</el-input>
{{- end }}
</el-form-item>
{{- end }}
+2 -11
View File
@@ -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)
+5 -6
View File
@@ -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
}