Skip to content

Commit

Permalink
Add cate controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuvist committed Mar 23, 2020
1 parent 7b32f5a commit 4536ebd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The idea is to build modularized & testable web applicaiton, and it's inspired b
* [ ] Add sql db to controller
* [ ] Add mock
* [ ] Add test case
* [ ] How to add multiple controller?
* [X] How to add multiple controller?
* [ ] provider set for controller
* [ ] How to make config loading as an lib?
* [X] refactor newWebApp with field injection
23 changes: 23 additions & 0 deletions controller/cate_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package controller

import (
"net/http"

"github.com/labstack/echo/v4"
)

// CateController handles blog category requests
type CateController struct {
}

func (controller *CateController) show(c echo.Context) error {
return c.String(http.StatusOK, "")
}

// NewCateController return CateController bind with echo engine
func NewCateController(e *echo.Echo) (*CateController, error) {
cate := &CateController{}
e.GET("/cate.go", cate.show)

return cate, nil
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WebApp struct {
*echo.Echo
config *conf.Config
blog *controller.BlogController
cate *controller.CateController
}

// Run the web app
Expand Down
5 changes: 3 additions & 2 deletions wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

func getWebApp() (*WebApp, error) {
wire.Build(newEcho, wire.Struct(new(WebApp), "*"), loadTomlConf,
controller.NewBlogController, newMsg)
wire.Build(newEcho, wire.Struct(new(WebApp), "*"), loadTomlConf, newMsg,
controller.NewBlogController,
controller.NewCateController)
return nil, nil
}
5 changes: 5 additions & 0 deletions wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4536ebd

Please sign in to comment.