Skip to content

Commit

Permalink
add comment for godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dingchaoyang committed Aug 4, 2020
1 parent ae5d1d1 commit d1e569e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/goslayer/layer/template/gtemplate.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,6 +18,8 @@ func main() {
r.Run(":8080")
}`
}

// RouterTemplate provides content for router.go file
func (gt GINTemplate) RouterTemplate() string {
return `package router
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/goslayer/layer/template/htemplate.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package template

// Template is a interface for providing some template func
type Template interface {
MainTemplate() string
RouterTemplate() string
Expand All @@ -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
Expand All @@ -27,6 +30,7 @@ func main() {
}`
}

// RouterTemplate provides content for router.go file
func (hht HttpHandlerTemplate) RouterTemplate() string {
return `package router
Expand All @@ -45,6 +49,7 @@ func init() {
}`
}

// BaseHandlerTemplate provides content for basehandler.go file
func (hht HttpHandlerTemplate) BaseHandlerTemplate() string {
return `package handler
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d1e569e

Please sign in to comment.