diff --git a/internal/goslayer/layer/template/gtemplate.go b/internal/goslayer/layer/template/gtemplate.go index 11a01c8..615f386 100644 --- a/internal/goslayer/layer/template/gtemplate.go +++ b/internal/goslayer/layer/template/gtemplate.go @@ -1,7 +1,9 @@ package template +// GINTemplate implements Template and provides some go files base on http.Handler building type GINTemplate struct{} +// MainTemplate provides content for main.go file func (gt GINTemplate) MainTemplate() string { return `package main @@ -16,6 +18,8 @@ func main() { r.Run(":8080") }` } + +// RouterTemplate provides content for router.go file func (gt GINTemplate) RouterTemplate() string { return `package router @@ -29,6 +33,8 @@ func Register(engine *gin.Engine) { engine.POST("goslayer/events/join", (&handler.EventHandler{}).JoinAEvent) }` } + +// BaseHandlerTemplate provides content for basehandler.go file func (gt GINTemplate) BaseHandlerTemplate() string { return `package handler @@ -59,6 +65,8 @@ func (baseh *BaseHandler) responseError(c *gin.Context, err error) { c.JSON(200, result) }` } + +// EventHandlerTemplate provides content for eventhandler.go file func (gt GINTemplate) EventHandlerTemplate() string { return `package handler @@ -83,9 +91,13 @@ func (eventh *EventHandler) JoinAEvent(c *gin.Context) { event.JoinAEvent(c.Query("event-id"), m) }` } + +// HttpMiddlewareTemplate provides content for middleware, but here is not implement func (gt GINTemplate) HttpMiddlewareTemplate() string { return `` } + +// EventBizTemplate provides content for business logic func (gt GINTemplate) EventBizTemplate() string { return `package event diff --git a/internal/goslayer/layer/template/htemplate.go b/internal/goslayer/layer/template/htemplate.go index 6ce22c8..0a76cd7 100644 --- a/internal/goslayer/layer/template/htemplate.go +++ b/internal/goslayer/layer/template/htemplate.go @@ -1,5 +1,6 @@ package template +// Template is a interface for providing some template func type Template interface { MainTemplate() string RouterTemplate() string @@ -9,8 +10,10 @@ type Template interface { EventBizTemplate() string } +// HttpHandlerTemplate implements Template and provides some go files base on http.Handler buildin type HttpHandlerTemplate struct{} +// MainTemplate provides content for main.go file func (hht HttpHandlerTemplate) MainTemplate() string { return `package main @@ -27,6 +30,7 @@ func main() { }` } +// RouterTemplate provides content for router.go file func (hht HttpHandlerTemplate) RouterTemplate() string { return `package router @@ -45,6 +49,7 @@ func init() { }` } +// BaseHandlerTemplate provides content for basehandler.go file func (hht HttpHandlerTemplate) BaseHandlerTemplate() string { return `package handler @@ -80,6 +85,7 @@ func (baseh *BaseHandler) responseError(rw http.ResponseWriter, err error) { }` } +// EventHandlerTemplate provides content for eventhandler.go file func (hht HttpHandlerTemplate) EventHandlerTemplate() string { return `package handler @@ -132,6 +138,7 @@ func (eventh *EventHandler) JoinAEvent(rw http.ResponseWriter, req *http.Request }` } +// HttpMiddlewareTemplate provides content for httpset.go file func (hht HttpHandlerTemplate) HttpMiddlewareTemplate() string { return `package middleware @@ -149,6 +156,7 @@ func HttpSet(hf func(http.ResponseWriter, *http.Request)) http.Handler { }` } +// EventBizTemplate provides content for business logic func (hht HttpHandlerTemplate) EventBizTemplate() string { return `package event