Skip to content

Commit

Permalink
router.go に切り分け
Browse files Browse the repository at this point in the history
  • Loading branch information
tatyam-prime committed Jun 16, 2022
1 parent 01dabab commit 912ca2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
27 changes: 6 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
21 changes: 21 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 912ca2c

Please sign in to comment.