From 4536ebd739fd2a65132faef053d305b7446cd41c Mon Sep 17 00:00:00 2001 From: Wuvist Date: Mon, 23 Mar 2020 11:26:58 +0800 Subject: [PATCH] Add cate controller --- README.md | 3 ++- controller/cate_controller.go | 23 +++++++++++++++++++++++ main.go | 1 + wire.go | 5 +++-- wire_gen.go | 5 +++++ 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 controller/cate_controller.go diff --git a/README.md b/README.md index 772caeb..2f91fbc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/controller/cate_controller.go b/controller/cate_controller.go new file mode 100644 index 0000000..0fc71bf --- /dev/null +++ b/controller/cate_controller.go @@ -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 +} diff --git a/main.go b/main.go index e01b80a..86dbd50 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ type WebApp struct { *echo.Echo config *conf.Config blog *controller.BlogController + cate *controller.CateController } // Run the web app diff --git a/wire.go b/wire.go index c449227..aeba18f 100644 --- a/wire.go +++ b/wire.go @@ -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 } diff --git a/wire_gen.go b/wire_gen.go index ecd244e..aea2a9b 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -22,10 +22,15 @@ func getWebApp() (*WebApp, error) { if err != nil { return nil, err } + cateController, err := controller.NewCateController(echo) + if err != nil { + return nil, err + } webApp := &WebApp{ Echo: echo, config: config, blog: blogController, + cate: cateController, } return webApp, nil }