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