clear:formatting code
This commit is contained in:
1 parent
426cec1b62
commit
8c554d7ee7
34 files changed
+260
-276
No files matched your search
@@ -7,3 +7,4 @@ temp/
|
||||
vendor
|
||||
config/settings.dev.yml
|
||||
go-admin
|
||||
middleware/demo.go
|
||||
@@ -47,7 +47,6 @@ func ServerInfo(c *gin.Context) {
|
||||
cpuDic := make(map[string]interface{}, 0)
|
||||
cpuDic["cpuNum"], _ = cpu.Counts(false)
|
||||
|
||||
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"os": osDic,
|
||||
|
||||
@@ -86,7 +86,7 @@ func GetConfigByConfigKey(c *gin.Context) {
|
||||
result, err := Config.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result,result.ConfigValue)
|
||||
app.OK(c, result, result.ConfigValue)
|
||||
}
|
||||
|
||||
// @Summary 添加配置
|
||||
@@ -107,7 +107,7 @@ func InsertConfig(c *gin.Context) {
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 修改配置
|
||||
@@ -127,7 +127,7 @@ func UpdateConfig(c *gin.Context) {
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.ConfigId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 删除配置
|
||||
@@ -145,5 +145,3 @@ func DeleteConfig(c *gin.Context) {
|
||||
tools.HasError(err, "修改失败", 500)
|
||||
app.OK(c, result, msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -26,17 +26,17 @@ func GetDeptList(c *gin.Context) {
|
||||
Dept.DataScope = tools.GetUserIdStr(c)
|
||||
result, err := Dept.SetDept(true)
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func GetDeptTree(c *gin.Context) {
|
||||
var Dept models.SysDept
|
||||
Dept.DeptName = c.Request.FormValue("deptName")
|
||||
Dept.Status= c.Request.FormValue("status")
|
||||
Dept.Status = c.Request.FormValue("status")
|
||||
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
||||
result, err := Dept.SetDept(false)
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 部门列表数据
|
||||
@@ -53,7 +53,7 @@ func GetDept(c *gin.Context) {
|
||||
Dept.DataScope = tools.GetUserIdStr(c)
|
||||
result, err := Dept.Get()
|
||||
tools.HasError(err, msg.NotFound, 404)
|
||||
app.OK(c,result, msg.GetSuccess)
|
||||
app.OK(c, result, msg.GetSuccess)
|
||||
}
|
||||
|
||||
// @Summary 添加部门
|
||||
@@ -73,7 +73,7 @@ func InsertDept(c *gin.Context) {
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result, msg.CreatedSuccess)
|
||||
app.OK(c, result, msg.CreatedSuccess)
|
||||
}
|
||||
|
||||
// @Summary 修改部门
|
||||
@@ -94,7 +94,7 @@ func UpdateDept(c *gin.Context) {
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.DeptId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result, msg.UpdatedSuccess)
|
||||
app.OK(c, result, msg.UpdatedSuccess)
|
||||
}
|
||||
|
||||
// @Summary 删除部门
|
||||
@@ -109,7 +109,7 @@ func DeleteDept(c *gin.Context) {
|
||||
id, err := tools.StringToInt(c.Param("id"))
|
||||
_, err = data.Delete(id)
|
||||
tools.HasError(err, "删除失败", 500)
|
||||
app.OK(c,"", msg.DeletedSuccess)
|
||||
app.OK(c, "", msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
func GetDeptTreeRoleselect(c *gin.Context) {
|
||||
@@ -124,7 +124,7 @@ func GetDeptTreeRoleselect(c *gin.Context) {
|
||||
menuIds, err = SysRole.GetRoleDeptId()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
}
|
||||
app.Custum(c,gin.H{
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"depts": result,
|
||||
"checkedKeys": menuIds,
|
||||
|
||||
@@ -148,5 +148,5 @@ func DeleteDictData(c *gin.Context) {
|
||||
IDS := tools.IdsStrToIdsIntGroup("dictCode", c)
|
||||
result, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, "修改失败", 500)
|
||||
app.OK(c,result,"删除成功")
|
||||
app.OK(c, result, "删除成功")
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package system
|
||||
|
||||
import(
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -33,8 +33,7 @@ $(function(){
|
||||
</html>
|
||||
`
|
||||
|
||||
|
||||
func HelloWorld(c *gin.Context){
|
||||
func HelloWorld(c *gin.Context) {
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
c.String(200, INDEX)
|
||||
}
|
||||
+4
-4
@@ -54,7 +54,7 @@ func GetPost(c *gin.Context) {
|
||||
Post.PostId, _ = tools.StringToInt(c.Param("postId"))
|
||||
result, err := Post.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 添加岗位
|
||||
@@ -74,7 +74,7 @@ func InsertPost(c *gin.Context) {
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result,"")
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
// @Summary 修改岗位
|
||||
@@ -95,7 +95,7 @@ func UpdatePost(c *gin.Context) {
|
||||
tools.HasError(err, "", -1)
|
||||
result, err := data.Update(data.PostId)
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c,result,"修改成功")
|
||||
app.OK(c, result, "修改成功")
|
||||
}
|
||||
|
||||
// @Summary 删除岗位
|
||||
@@ -111,5 +111,5 @@ func DeletePost(c *gin.Context) {
|
||||
IDS := tools.IdsStrToIdsIntGroup("postId", c)
|
||||
result, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, "删除失败", 500)
|
||||
app.OK(c,result,"删除成功")
|
||||
app.OK(c, result, "删除成功")
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func GetDBColumnList(c *gin.Context) {
|
||||
}
|
||||
|
||||
data.TableName = c.Request.FormValue("tableName")
|
||||
tools2.Assert(data.TableName=="","table name cannot be empty!",500)
|
||||
tools2.Assert(data.TableName == "", "table name cannot be empty!", 500)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
tools2.HasError(err, "", -1)
|
||||
|
||||
|
||||
+6
-6
@@ -73,8 +73,8 @@ func GenCode(c *gin.Context) {
|
||||
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
|
||||
_ = tools2.PathCreate("./models/")
|
||||
_ = tools2.PathCreate("./router/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/api/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath+"/views/"+tab.PackageName)
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
|
||||
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
|
||||
|
||||
var b1 bytes.Buffer
|
||||
err = t1.Execute(&b1, tab)
|
||||
@@ -92,15 +92,15 @@ func GenCode(c *gin.Context) {
|
||||
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
|
||||
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
|
||||
|
||||
oldTest:="// {{认证路由自动补充在此处请勿删除}}"
|
||||
newText:="// {{认证路由自动补充在此处请勿删除}} \r\n register"+tab.ClassName+"Router(v1,authMiddleware)"
|
||||
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
|
||||
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
|
||||
|
||||
helper := tools2.ReplaceHelper{
|
||||
Root: "./router/router.go",
|
||||
OldText:oldTest,
|
||||
OldText: oldTest,
|
||||
NewText: newText,
|
||||
}
|
||||
if helper.OldText == helper.NewText{
|
||||
if helper.OldText == helper.NewText {
|
||||
log.Println("error !! the NewText isEqual the OldText")
|
||||
return
|
||||
}
|
||||
|
||||
+8
-8
@@ -18,9 +18,9 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
)
|
||||
|
||||
var (
|
||||
var (
|
||||
configYml string
|
||||
port string
|
||||
mode string
|
||||
@@ -36,20 +36,20 @@ import (
|
||||
return run()
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
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")
|
||||
StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod")
|
||||
}
|
||||
}
|
||||
|
||||
func usage() {
|
||||
func usage() {
|
||||
usageStr := `starting api server`
|
||||
log.Printf("%s\n", usageStr)
|
||||
}
|
||||
}
|
||||
|
||||
func setup() {
|
||||
func setup() {
|
||||
//1. 读取配置
|
||||
config.ConfigSetup(configYml)
|
||||
//2. 设置日志
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package database
|
||||
|
||||
|
||||
func Setup(driver string) {
|
||||
dbType := driver
|
||||
if dbType == "mysql" {
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
var RequestLogger = &logrus.Entry{}
|
||||
|
||||
|
||||
|
||||
func init() {
|
||||
// TODO: requestLogger log format
|
||||
// RequestLogger = logrus.WithFields(logrus.Fields{"request_id": request_id, "user_ip": user_ip})
|
||||
|
||||
@@ -153,7 +153,6 @@ func RAMCheck(c *gin.Context) {
|
||||
text = "WARNING"
|
||||
}
|
||||
|
||||
|
||||
app.Custum(c, gin.H{
|
||||
"code": 200,
|
||||
"msg": text,
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(role.DataScope)
|
||||
table,err := dataPermission.GetDataScope("sys_role", table)
|
||||
table, err := dataPermission.GetDataScope("sys_role", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ type SysUserB struct {
|
||||
BaseModel
|
||||
}
|
||||
|
||||
|
||||
type SysUser struct {
|
||||
SysUserId
|
||||
SysUserB
|
||||
|
||||
@@ -24,8 +24,6 @@ e = some(where (p.eft == allow))
|
||||
m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")
|
||||
`
|
||||
|
||||
|
||||
|
||||
func Setup() {
|
||||
Apter, err := gormAdapter.NewAdapterByDB(global.Eloquent)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,5 @@ import (
|
||||
var (
|
||||
Info *log.Logger
|
||||
Warning *log.Logger
|
||||
Error * log.Logger
|
||||
Error *log.Logger
|
||||
)
|
||||
|
||||
|
||||
+1
-6
@@ -7,8 +7,6 @@ import (
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// 路由示例
|
||||
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
|
||||
|
||||
@@ -32,10 +30,7 @@ func examplesNoCheckRoleRouter(r *gin.Engine) {
|
||||
// 需要认证的路由示例
|
||||
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||
v1 := r.Group("/api/v1")
|
||||
v1.GET("/checkrole",nil)
|
||||
v1.GET("/checkrole", nil)
|
||||
|
||||
// {{认证路由自动补充在此处请勿删除}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+58
-58
@@ -7,7 +7,7 @@ _ "time"
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
{{ range .Columns -}}
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}}
|
||||
@@ -16,34 +16,34 @@ type {{.ClassName}} struct {
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}}
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func ({{.ClassName}}) TableName() string {
|
||||
return "{{.TBName}}"
|
||||
return "{{.TBName}}"
|
||||
}
|
||||
|
||||
// 创建{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
var doc {{.ClassName}}
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
|
||||
// 获取{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
@@ -54,72 +54,72 @@ var doc {{.ClassName}}
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}带分页
|
||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
|
||||
var doc []{{.ClassName}}
|
||||
var doc []{{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
{{ range .Columns }}
|
||||
{{- if .IsQuery }}
|
||||
if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
|
||||
table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
|
||||
}
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/{{.ModuleName}}"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/middleware"
|
||||
"go-admin/apis/{{.ModuleName}}"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
// 需认证的路由代码
|
||||
|
||||
+40
-24
@@ -7,9 +7,11 @@
|
||||
{{- if ($x) -}}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{if eq .DictType "" -}}
|
||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
|
||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
|
||||
size="small" @keyup.enter.native="handleQuery"/>
|
||||
{{- else -}}
|
||||
<el-select v-model="queryParams.{{.JsonField}}" placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
||||
<el-select v-model="queryParams.{{.JsonField}}"
|
||||
placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
:key="dict.dictValue"
|
||||
@@ -35,7 +37,8 @@
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
>新增</el-button>
|
||||
>新增
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@@ -45,7 +48,8 @@
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@@ -55,24 +59,27 @@
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="{{.ModuleName}}List" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column type="selection" width="55" align="center"/>
|
||||
{{- range .Columns -}}
|
||||
{{- $x := .IsList -}}
|
||||
{{- if ($x) }}
|
||||
{{- if ne .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:formatter="{{.JsonField}}Format" width="100">
|
||||
<template slot-scope="scope">
|
||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
{{- end -}}
|
||||
{{- if eq .DictType "" -}}
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
||||
:show-overflow-tooltip="true"/>
|
||||
{{- end -}}
|
||||
|
||||
{{- end }}
|
||||
@@ -85,14 +92,16 @@
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
<el-button
|
||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -118,13 +127,15 @@
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else }}
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}" >
|
||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
||||
{{ if eq "input" .HtmlType -}}
|
||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}" {{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
||||
<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}}" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
||||
<el-option label="demo1" value="demo1"/>
|
||||
<el-option label="demo2" value="demo2"/>
|
||||
</el-select>
|
||||
{{- else if eq "radio" .HtmlType -}}
|
||||
<el-radio-group v-model="form.{{.JsonField}}">
|
||||
@@ -149,7 +160,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { list{{.ClassName}}, get{{.ClassName}}, del{{.ClassName}}, add{{.ClassName}}, update{{.ClassName}} } from '@/api/{{.PackageName}}'
|
||||
import {add, del, get, list, update} from '@/api/'
|
||||
|
||||
export default {
|
||||
name: 'Config',
|
||||
@@ -172,7 +183,7 @@
|
||||
isEdit: false,
|
||||
// 类型数据字典
|
||||
typeOptions: [],
|
||||
{{.ModuleName}}List:[],
|
||||
{{.ModuleName}}List: [],
|
||||
{{range .Columns}}
|
||||
{{- if ne .DictType "" -}}
|
||||
{{.JsonField}}Options: [],
|
||||
@@ -184,13 +195,15 @@
|
||||
pageSize: 10,
|
||||
{{ range .Columns }}
|
||||
{{- if (.IsQuery) -}}
|
||||
{{.JsonField}}:undefined,
|
||||
{{.JsonField}}:
|
||||
undefined,
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
},
|
||||
}
|
||||
,
|
||||
// 表单校验
|
||||
rules: {
|
||||
{{- range .Columns -}}
|
||||
@@ -243,7 +256,8 @@
|
||||
{{- else if eq .GoField "UpdateBy" -}}
|
||||
{{- else if eq .GoField "CreateBy" -}}
|
||||
{{- else }}
|
||||
{{.JsonField}}: undefined,
|
||||
{{.JsonField}}:
|
||||
undefined,
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
@@ -285,7 +299,8 @@
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
const {{.PkJsonField}} = row.{{.PkJsonField}} || this.ids
|
||||
const {{.PkJsonField}} =
|
||||
row.{{.PkJsonField}} || this.ids
|
||||
get{{.ClassName}}({{.PkJsonField}}).then(response => {
|
||||
this.form = response.data
|
||||
this.open = true
|
||||
@@ -294,7 +309,7 @@
|
||||
})
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
submitForm: function () {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.{{.PkJsonField}} !== undefined) {
|
||||
@@ -328,12 +343,13 @@
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function() {
|
||||
}).then(function () {
|
||||
return del{{.ClassName}}(Ids)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.msgSuccess('删除成功')
|
||||
}).catch(function() {})
|
||||
}).catch(function () {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+56
-56
@@ -21,40 +21,40 @@ import (
|
||||
// @Router /api/v1/configList [get]
|
||||
// @Security Bearer
|
||||
func Get{{.ClassName}}List(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
var data models.{{.ClassName}}
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = pkg.StrToInt(err, size)
|
||||
}
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = pkg.StrToInt(err, size)
|
||||
}
|
||||
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = pkg.StrToInt(err, index)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = pkg.StrToInt(err, index)
|
||||
}
|
||||
|
||||
{{ range .Columns -}}
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}
|
||||
data.{{.GoField}} = c.Request.FormValue("{{.JsonField}}")
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.HasError(err, "", -1)
|
||||
data.DataScope = utils.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
var mp = make(map[string]interface{}, 3)
|
||||
mp["list"] = result
|
||||
mp["count"] = count
|
||||
mp["pageIndex"] = pageIndex
|
||||
mp["pageIndex"] = pageSize
|
||||
|
||||
var res app.Response
|
||||
res.Data = mp
|
||||
var res app.Response
|
||||
res.Data = mp
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 获取配置
|
||||
@@ -65,15 +65,15 @@ func Get{{.ClassName}}List(c *gin.Context) {
|
||||
// @Router /api/v1/config/{configId} [get]
|
||||
// @Security Bearer
|
||||
func Get{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
result, err := data.Get()
|
||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
||||
var data models.{{.ClassName}}
|
||||
data.{{.PkGoField}}, _ = utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
result, err := data.Get()
|
||||
pkg.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 添加配置
|
||||
@@ -87,40 +87,40 @@ func Get{{.ClassName}}(c *gin.Context) {
|
||||
// @Router /api/v1/dict/data [post]
|
||||
// @Security Bearer
|
||||
func Insert{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
pkg.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.HasError(err, "", -1)
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
data.CreateBy = utils.GetUserIdStr(c)
|
||||
pkg.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
|
||||
}
|
||||
|
||||
func Update{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
pkg.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.{{.PkGoField}})
|
||||
pkg.HasError(err, "", -1)
|
||||
var data models.{{.ClassName}}
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
pkg.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
result, err := data.Update(data.{{.PkGoField}})
|
||||
pkg.HasError(err, "", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func Delete{{.ClassName}}(c *gin.Context) {
|
||||
var data models.{{.ClassName}}
|
||||
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.HasError(err, "修改失败", 500)
|
||||
var data models.{{.ClassName}}
|
||||
id, err := utils.StringToInt(c.Param("{{.PkJsonField}}"))
|
||||
data.UpdateBy = utils.GetUserIdStr(c)
|
||||
_, err = data.Delete(id)
|
||||
pkg.HasError(err, "修改失败", 500)
|
||||
|
||||
var res app.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
var res app.Response
|
||||
res.Msg = "删除成功"
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
||||
func TestGoModelTemplate(t *testing.T) {
|
||||
t1, err := template.ParseFiles("model.go.template")
|
||||
if err != nil {
|
||||
|
||||
+56
-56
@@ -1,104 +1,104 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/utils"
|
||||
"time"
|
||||
orm "go-admin/global"
|
||||
"go-admin/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
|
||||
{{ range .Columns -}}
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
// {{.ColumnComment}}
|
||||
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"column:{{.ColumnName}};"`{{end}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
}
|
||||
|
||||
// 创建{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
doc.IsDel = "0"
|
||||
e.CreateTime = time.Now().String()
|
||||
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
var doc {{.ClassName}}
|
||||
doc.IsDel = "0"
|
||||
e.CreateTime = time.Now().String()
|
||||
result := orm.Eloquent.Table("{{.TableName}}").Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
var doc {{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
table := orm.Eloquent.Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取{{.ClassName}}带分页
|
||||
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int32, error) {
|
||||
var doc []{{.ClassName}}
|
||||
var doc []{{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
table := orm.Eloquent.Select("*").Table("{{.TableName}}")
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}if e.{{.GoField}} != "" {
|
||||
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
|
||||
}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int32
|
||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = utils.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope("{{.TableName}}", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int32
|
||||
table = table.Offset((pageIndex - 1) * pageSize).Limit(pageSize)
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
|
||||
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
if err = orm.Eloquent.Table("{{.TableName}}").Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ type PageResponse struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
|
||||
func (res *Response) ReturnOK() *Response {
|
||||
res.Code = 200
|
||||
return res
|
||||
@@ -36,11 +35,7 @@ func (res *Response) ReturnError(code int) *Response {
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
func (res *PageResponse) ReturnOK() *PageResponse {
|
||||
res.Code = 200
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ func OK(c *gin.Context, data interface{}, msg string) {
|
||||
}
|
||||
|
||||
// 分页数据处理
|
||||
func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize int, msg string) {
|
||||
func PageOK(c *gin.Context, result interface{}, count int, pageIndex int, pageSize int, msg string) {
|
||||
var res PageResponse
|
||||
res.Data.List = result
|
||||
res.Data.Count = count
|
||||
@@ -40,5 +40,5 @@ func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize
|
||||
|
||||
// 兼容函数
|
||||
func Custum(c *gin.Context, data gin.H) {
|
||||
c.JSON(http.StatusOK,data)
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
@@ -20,9 +20,8 @@ type configJsonBody struct {
|
||||
DriverDigit *base64Captcha.DriverDigit
|
||||
}
|
||||
|
||||
|
||||
func DriverStringFunc() (id, b64s string, err error) {
|
||||
e :=configJsonBody{}
|
||||
e := configJsonBody{}
|
||||
e.Id = uuid.New().String()
|
||||
e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
|
||||
driver := e.DriverString.ConvertFonts()
|
||||
@@ -30,7 +29,6 @@ func DriverStringFunc() (id, b64s string, err error) {
|
||||
return cap.Generate()
|
||||
}
|
||||
|
||||
|
||||
func DriverDigitFunc() (id, b64s string, err error) {
|
||||
e := configJsonBody{}
|
||||
e.Id = uuid.New().String()
|
||||
|
||||
@@ -41,7 +41,7 @@ func portDefault(cfg *viper.Viper) string {
|
||||
}
|
||||
|
||||
func isHttpsDefault(cfg *viper.Viper) bool {
|
||||
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false{
|
||||
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
|
||||
@@ -16,7 +16,6 @@ var cfgLog *viper.Viper
|
||||
var cfgSsl *viper.Viper
|
||||
var cfgGen *viper.Viper
|
||||
|
||||
|
||||
//载入配置文件
|
||||
func ConfigSetup(path string) {
|
||||
viper.SetConfigFile(path)
|
||||
@@ -25,7 +24,6 @@ func ConfigSetup(path string) {
|
||||
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
|
||||
}
|
||||
|
||||
|
||||
//Replace environment variables
|
||||
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
|
||||
if err != nil {
|
||||
@@ -69,7 +67,6 @@ func ConfigSetup(path string) {
|
||||
GenConfig = InitGen(cfgGen)
|
||||
}
|
||||
|
||||
|
||||
func SetConfig(configPath string, key string, value interface{}) {
|
||||
viper.AddConfigPath(configPath)
|
||||
viper.Set(key, value)
|
||||
|
||||
@@ -19,4 +19,3 @@ func InitDatabase(cfg *viper.Viper) *Database {
|
||||
}
|
||||
|
||||
var DatabaseConfig = new(Database)
|
||||
|
||||
+5
-4
@@ -55,7 +55,7 @@ func FileRemove(name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func FileZip(dst, src string,notContPath string) (err error) {
|
||||
func FileZip(dst, src string, notContPath string) (err error) {
|
||||
//创建准备写入的文件
|
||||
fw, err := os.Create(dst)
|
||||
defer fw.Close()
|
||||
@@ -119,6 +119,7 @@ type ReplaceHelper struct {
|
||||
OldText string //需要替换的文本
|
||||
NewText string //新的文本
|
||||
}
|
||||
|
||||
func (h *ReplaceHelper) DoWrok() error {
|
||||
|
||||
return filepath.Walk(h.Root, h.walkCallback)
|
||||
@@ -134,7 +135,7 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
||||
return nil
|
||||
}
|
||||
if f.IsDir() {
|
||||
log.Println("DIR:",path)
|
||||
log.Println("DIR:", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -146,8 +147,8 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
|
||||
return err
|
||||
}
|
||||
content := string(buf)
|
||||
log.Printf("h.OldText: %s \n",h.OldText)
|
||||
log.Printf("h.NewText: %s \n",h.NewText)
|
||||
log.Printf("h.OldText: %s \n", h.OldText)
|
||||
log.Printf("h.NewText: %s \n", h.NewText)
|
||||
|
||||
//替换
|
||||
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
|
||||
|
||||
@@ -14,7 +14,6 @@ func InitLogger() {
|
||||
log.FieldKeyLevel: "@level",
|
||||
log.FieldKeyMsg: "@message"}})
|
||||
|
||||
|
||||
switch Mode(config2.ApplicationConfig.Mode) {
|
||||
case ModeDev, ModeTest:
|
||||
log.SetOutput(os.Stdout)
|
||||
|
||||
@@ -17,7 +17,6 @@ func StringToInt(e string) (int, error) {
|
||||
return strconv.Atoi(e)
|
||||
}
|
||||
|
||||
|
||||
func GetCurrentTimeStr() string {
|
||||
return time.Now().Format("2006/01/02 15:04:05")
|
||||
}
|
||||
@@ -26,7 +25,6 @@ func GetCurrentTime() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
|
||||
func StructToJsonStr(e interface{}) (string, error) {
|
||||
if b, err := json.Marshal(e); err == nil {
|
||||
return string(b), err
|
||||
|
||||
@@ -10,7 +10,6 @@ func IdsStrToIdsIntGroup(key string, c *gin.Context) []int {
|
||||
return idsStrToIdsIntGroup(c.Param(key))
|
||||
}
|
||||
|
||||
|
||||
func idsStrToIdsIntGroup(keys string) []int {
|
||||
IDS := make([]int, 0)
|
||||
ids := strings.Split(keys, ",")
|
||||
|
||||
Reference in new issue
Block a user