Skip to content

Commit 1ec05e3

Browse files
committed
main.goからechoへの依存排除
1 parent c9a73fb commit 1ec05e3

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

main.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"os"
88
"runtime"
99

10-
"github.com/labstack/echo"
11-
"github.com/labstack/echo/middleware"
12-
1310
"github.com/traPtitech/anke-to/model"
1411
"github.com/traPtitech/anke-to/tuning"
1512
)
@@ -44,18 +41,6 @@ func main() {
4441
db.LogMode(true)
4542
}
4643

47-
e := echo.New()
48-
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
49-
AllowOrigins: []string{"http://localhost:8080"},
50-
AllowCredentials: true,
51-
}))
52-
53-
// Middleware
54-
e.Use(middleware.Recover())
55-
e.Use(middleware.Logger())
56-
57-
SetRouting(e)
58-
5944
if env == "pprof" {
6045
runtime.SetBlockProfileRate(1)
6146
go func() {
@@ -64,6 +49,6 @@ func main() {
6449
}
6550

6651
port := os.Getenv("PORT")
67-
// Start server
68-
e.Logger.Fatal(e.Start(port))
52+
53+
SetRouting(port)
6954
}

router.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@ package main
22

33
import (
44
"github.com/labstack/echo"
5+
"github.com/labstack/echo/middleware"
56
)
67

78
// SetRouting ルーティングの設定
8-
func SetRouting(e *echo.Echo) {
9+
func SetRouting(port string) {
10+
e := echo.New()
11+
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
12+
AllowOrigins: []string{"http://localhost:8080"},
13+
AllowCredentials: true,
14+
}))
15+
16+
// Middleware
17+
e.Use(middleware.Recover())
18+
e.Use(middleware.Logger())
19+
920
api := InjectAPIServer()
1021

1122
// Static Files
@@ -68,4 +79,6 @@ func SetRouting(e *echo.Echo) {
6879
apiResults.GET("/:questionnaireID", api.GetResults)
6980
}
7081
}
82+
83+
e.Logger.Fatal(e.Start(port))
7184
}

0 commit comments

Comments
 (0)