-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (46 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"github.com/traPtitech/game3-back/internal/handler"
"github.com/traPtitech/game3-back/internal/migration"
"github.com/traPtitech/game3-back/internal/pkg/config"
"github.com/traPtitech/game3-back/internal/pkg/util"
"github.com/traPtitech/game3-back/internal/repository"
"github.com/traPtitech/game3-back/openapi"
"os"
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
swagger, err := openapi.GetSwagger()
if err != nil {
fmt.Printf("Error loading swagger spec\n: %s", err)
os.Exit(1)
}
baseURL := "/api"
swagger.Servers = openapi3.Servers{&openapi3.Server{URL: baseURL}}
// middlewares
e.Use(middleware.Recover())
e.Use(middleware.Logger())
//e.Use(oapimiddleware.OapiRequestValidator(swagger))
// connect to database
db, err := sqlx.Connect("mysql", config.MySQL().FormatDSN())
if err != nil {
e.Logger.Fatal(err)
}
defer db.Close()
sqlx.NameMapper = util.ToSnakeCase
// migrate tables
if err := migration.MigrateTables(db.DB); err != nil {
e.Logger.Fatal(err)
}
// setup repository
repo := repository.New(db)
// setup routes
h := handler.New(repo)
openapi.RegisterHandlersWithBaseURL(e, h, baseURL)
e.Logger.Fatal(e.Start(config.AppAddr()))
}