✨ init project
This commit is contained in:
44
resource/function/api.go.tpl
Normal file
44
resource/function/api.go.tpl
Normal file
@@ -0,0 +1,44 @@
|
||||
{{if .IsPlugin}}
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary {{.FuncDesc}}
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
func (a *{{.Abbreviation}}) {{.FuncName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
// 请添加自己的业务逻辑
|
||||
err := service{{ .StructName }}.{{.FuncName}}(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData("返回数据",c)
|
||||
}
|
||||
|
||||
{{- else -}}
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary {{.FuncDesc}}
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query {{.Package}}Req.{{.StructName}}Search true "成功"
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api){{.FuncName}}(c *gin.Context) {
|
||||
// 创建业务用Context
|
||||
ctx := c.Request.Context()
|
||||
// 请添加自己的业务逻辑
|
||||
err := {{.Abbreviation}}Service.{{.FuncName}}(ctx)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData("返回数据",c)
|
||||
}
|
||||
{{end}}
|
32
resource/function/api.js.tpl
Normal file
32
resource/function/api.js.tpl
Normal file
@@ -0,0 +1,32 @@
|
||||
{{if .IsPlugin}}
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary {{.FuncDesc}}
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
export const {{.Router}} = () => {
|
||||
return service({
|
||||
url: '/{{.Abbreviation}}/{{.Router}}',
|
||||
method: '{{.Method}}'
|
||||
})
|
||||
}
|
||||
|
||||
{{- else -}}
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// @Tags {{.StructName}}
|
||||
// @Summary {{.FuncDesc}}
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "成功"
|
||||
// @Router /{{.Abbreviation}}/{{.Router}} [{{.Method}}]
|
||||
export const {{.Router}} = () => {
|
||||
return service({
|
||||
url: '/{{.Abbreviation}}/{{.Router}}',
|
||||
method: '{{.Method}}'
|
||||
})
|
||||
}
|
||||
|
||||
{{- end -}}
|
25
resource/function/server.go.tpl
Normal file
25
resource/function/server.go.tpl
Normal file
@@ -0,0 +1,25 @@
|
||||
{{- $db := "" }}
|
||||
{{- if eq .BusinessDB "" }}
|
||||
{{- $db = "global.GVA_DB" }}
|
||||
{{- else}}
|
||||
{{- $db = printf "global.MustGetGlobalDBByDBName(\"%s\")" .BusinessDB }}
|
||||
{{- end}}
|
||||
{{if .IsPlugin}}
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func (s *{{.Abbreviation}}) {{.FuncName}}(ctx context.Context) (err error) {
|
||||
db := {{$db}}.Model(&model.{{.StructName}}{})
|
||||
return db.Error
|
||||
}
|
||||
|
||||
{{- else -}}
|
||||
|
||||
// {{.FuncName}} {{.FuncDesc}}
|
||||
// Author [yourname](https://github.com/yourname)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service){{.FuncName}}(ctx context.Context) (err error) {
|
||||
// 请在这里实现自己的业务逻辑
|
||||
db := {{$db}}.Model(&{{.Package}}.{{.StructName}}{})
|
||||
return db.Error
|
||||
}
|
||||
{{end}}
|
Reference in New Issue
Block a user