✨ Init
This commit is contained in:
35
resource/plug_template/api/api.go.tpl
Normal file
35
resource/plug_template/api/api.go.tpl
Normal file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
"miniapp/model/common/response"
|
||||
{{ if .NeedModel }} "miniapp/plugin/{{ .Snake}}/model" {{ end }}
|
||||
"miniapp/plugin/{{ .Snake}}/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Api struct{}
|
||||
|
||||
// @Tags {{ .PlugName}}
|
||||
// @Summary 请手动填写接口功能
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
|
||||
// @Router /{{ .RouterGroup}}/routerName [post]
|
||||
func (p *{{ .PlugName}}Api) ApiName(c *gin.Context) {
|
||||
{{ if .HasRequest}}
|
||||
var plug model.Request
|
||||
_ = c.ShouldBindJSON(&plug)
|
||||
{{ end }}
|
||||
if {{ if .HasResponse }} res, {{ end }} err:= service.ServiceGroupApp.PlugService({{ if .HasRequest }}plug{{ end -}}); err != nil {
|
||||
global.GVA_LOG.Error("失败!", zap.Error(err))
|
||||
response.FailWithMessage("失败", c)
|
||||
} else {
|
||||
{{if .HasResponse }}
|
||||
response.OkWithDetailed(res,"成功",c)
|
||||
{{else}}
|
||||
response.OkWithData("成功", c)
|
||||
{{ end -}}
|
||||
|
||||
}
|
||||
}
|
7
resource/plug_template/api/enter.go.tpl
Normal file
7
resource/plug_template/api/enter.go.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
package api
|
||||
|
||||
type ApiGroup struct {
|
||||
{{ .PlugName}}Api
|
||||
}
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
9
resource/plug_template/config/config.go.tpl
Normal file
9
resource/plug_template/config/config.go.tpl
Normal file
@@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
{{- if .HasGlobal }}
|
||||
type {{ .PlugName }} struct {
|
||||
{{- range .Global }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
8
resource/plug_template/global/global.go.tpl
Normal file
8
resource/plug_template/global/global.go.tpl
Normal file
@@ -0,0 +1,8 @@
|
||||
package global
|
||||
|
||||
{{- if .HasGlobal }}
|
||||
|
||||
import "miniapp/plugin/{{ .Snake}}/config"
|
||||
|
||||
var GlobalConfig = new(config.{{ .PlugName}})
|
||||
{{ end -}}
|
29
resource/plug_template/main.go.tpl
Normal file
29
resource/plug_template/main.go.tpl
Normal file
@@ -0,0 +1,29 @@
|
||||
package {{ .Snake}}
|
||||
|
||||
import (
|
||||
{{- if .HasGlobal }}
|
||||
"miniapp/plugin/{{ .Snake}}/global"
|
||||
{{- end }}
|
||||
"miniapp/plugin/{{ .Snake}}/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Plugin struct {
|
||||
}
|
||||
|
||||
func Create{{ .PlugName}}Plug({{- range .Global}} {{.Key}} {{.Type}}, {{- end }})*{{ .PlugName}}Plugin {
|
||||
{{- if .HasGlobal }}
|
||||
{{- range .Global}}
|
||||
global.GlobalConfig.{{.Key}} = {{.Key}}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
return &{{ .PlugName}}Plugin{}
|
||||
}
|
||||
|
||||
func (*{{ .PlugName}}Plugin) Register(group *gin.RouterGroup) {
|
||||
router.RouterGroupApp.Init{{ .PlugName}}Router(group)
|
||||
}
|
||||
|
||||
func (*{{ .PlugName}}Plugin) RouterPath() string {
|
||||
return "{{ .RouterGroup}}"
|
||||
}
|
17
resource/plug_template/model/model.go.tpl
Normal file
17
resource/plug_template/model/model.go.tpl
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
{{- if .HasRequest }}
|
||||
type Request struct {
|
||||
{{- range .Request }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
{{- if .HasResponse }}
|
||||
type Response struct {
|
||||
{{- range .Response }}
|
||||
{{ .Key }} {{ .Type }} {{- if ne .Desc "" }} // {{ .Desc }} {{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end -}}
|
7
resource/plug_template/router/enter.go.tpl
Normal file
7
resource/plug_template/router/enter.go.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
package router
|
||||
|
||||
type RouterGroup struct {
|
||||
{{ .PlugName}}Router
|
||||
}
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
17
resource/plug_template/router/router.go.tpl
Normal file
17
resource/plug_template/router/router.go.tpl
Normal file
@@ -0,0 +1,17 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"miniapp/plugin/{{ .Snake}}/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type {{ .PlugName}}Router struct {
|
||||
}
|
||||
|
||||
func (s *{{ .PlugName}}Router) Init{{ .PlugName}}Router(Router *gin.RouterGroup) {
|
||||
plugRouter := Router
|
||||
plugApi := api.ApiGroupApp.{{ .PlugName}}Api
|
||||
{
|
||||
plugRouter.POST("routerName", plugApi.ApiName)
|
||||
}
|
||||
}
|
7
resource/plug_template/service/enter.go.tpl
Normal file
7
resource/plug_template/service/enter.go.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
package service
|
||||
|
||||
type ServiceGroup struct {
|
||||
{{ .PlugName}}Service
|
||||
}
|
||||
|
||||
var ServiceGroupApp = new(ServiceGroup)
|
14
resource/plug_template/service/service.go.tpl
Normal file
14
resource/plug_template/service/service.go.tpl
Normal file
@@ -0,0 +1,14 @@
|
||||
package service
|
||||
|
||||
{{- if .NeedModel }}
|
||||
import (
|
||||
"miniapp/plugin/{{ .Snake}}/model"
|
||||
)
|
||||
{{ end }}
|
||||
|
||||
type {{ .PlugName}}Service struct{}
|
||||
|
||||
func (e *{{ .PlugName}}Service) PlugService({{- if .HasRequest }}req model.Request {{ end -}}) ({{- if .HasResponse }}res model.Response,{{ end -}} err error) {
|
||||
// 写你的业务逻辑
|
||||
return {{- if .HasResponse }} res,{{ end }} nil
|
||||
}
|
Reference in New Issue
Block a user