From 912ca2caa983cdfffb854da21a9f09b0466a895e Mon Sep 17 00:00:00 2001 From: tatyam Date: Thu, 16 Jun 2022 22:55:53 +0900 Subject: [PATCH] =?UTF-8?q?router.go=20=E3=81=AB=E5=88=87=E3=82=8A?= =?UTF-8?q?=E5=88=86=E3=81=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 27 ++++++--------------------- router/router.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 router/router.go diff --git a/main.go b/main.go index ce87c32..66fc0bb 100644 --- a/main.go +++ b/main.go @@ -2,31 +2,16 @@ package main import ( "fmt" - "net/http" - "os" - - "github.com/labstack/echo/v4" "github.com/hackathon-22-spring-16/backend/model" + "github.com/hackathon-22-spring-16/backend/router" ) func main() { - db, err := model.InitDB() - - e := echo.New() - e.GET("/ping", func(c echo.Context) error { - return c.String(http.StatusOK, "pong") - }) - e.GET("/db-info", func(c echo.Context) error { - if err != nil { - return c.String(http.StatusInternalServerError, fmt.Sprintf("db error: %s", err)) - } - return c.String(http.StatusOK, fmt.Sprintf("driver name: %s", db.DriverName())) - }) - - port := os.Getenv("PORT") - if port == "" { - port = ":3000" + _, err := model.InitDB() + if err != nil { + panic(fmt.Errorf("db error: %w", err)) } - e.Start(port) + + router.SetRouting() } diff --git a/router/router.go b/router/router.go new file mode 100644 index 0000000..e1f4cc7 --- /dev/null +++ b/router/router.go @@ -0,0 +1,21 @@ +package router + +import ( + "net/http" + "os" + + "github.com/labstack/echo/v4" +) + +func SetRouting() { + e := echo.New() + e.GET("/ping", func(c echo.Context) error { + return c.String(http.StatusOK, "pong") + }) + + port := os.Getenv("PORT") + if port == "" { + port = ":3000" + } + e.Start(port) +} \ No newline at end of file