From 5685d2580a29a75e401f0ff5c1196bc00cd2f492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Fri, 18 Mar 2022 13:26:13 +0100 Subject: [PATCH] Refactor: Moving route methods from server.go to app.go --- server/app.go | 29 +++++++++++++++++++++++++++++ server/server.go | 23 ----------------------- 2 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 server/app.go diff --git a/server/app.go b/server/app.go new file mode 100644 index 0000000..4fd02ad --- /dev/null +++ b/server/app.go @@ -0,0 +1,29 @@ +package server + +import ( + "fmt" + "github.com/labstack/echo/v4" + "log" + "net/http" +) + +func WikiHome(c echo.Context) error { + res := store.GetPage() + fmt.Println(res) + return c.String(http.StatusOK, "WikiHome") +} + +func WikiAbout(c echo.Context) error { + id := c.Param("id") + return c.String(http.StatusOK, "About the wiki. id:"+id) +} + +func WikiListPages(c echo.Context) error { + fmt.Println("WikiListPages") + res, err := store.GetAllPages() + if err != nil { + log.Panicln(err) + } + fmt.Println(res) + return c.String(http.StatusOK, "WikiListPages") +} diff --git a/server/server.go b/server/server.go index 215ac40..2d65c28 100644 --- a/server/server.go +++ b/server/server.go @@ -1,11 +1,9 @@ package server import ( - "fmt" "github.com/labstack/echo/v4" "github.com/oscarmlage/wikingo/model" "log" - "net/http" ) // Depending on config we should open one store or other (Gorm, File, @@ -33,24 +31,3 @@ func Serve() { // Logger e.Logger.Fatal(e.Start(":2323")) } - -func WikiHome(c echo.Context) error { - res := store.GetPage() - fmt.Println(res) - return c.String(http.StatusOK, "WikiHome") -} - -func WikiAbout(c echo.Context) error { - id := c.Param("id") - return c.String(http.StatusOK, "About the wiki. id:"+id) -} - -func WikiListPages(c echo.Context) error { - fmt.Println("WikiListPages") - res, err := store.GetAllPages() - if err != nil { - log.Panicln(err) - } - fmt.Println(res) - return c.String(http.StatusOK, "WikiListPages") -}