-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1.07 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
package main
import (
"fmt"
"log"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/internal/handler"
"github.com/traPtitech/traPortfolio/internal/infrastructure/repository"
"github.com/traPtitech/traPortfolio/internal/pkgs/config"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
)
func main() {
appConf, err := config.Load(config.LoadOpts{})
if err != nil {
log.Fatal(err)
}
db, err := repository.NewGormDB(appConf.DB)
if err != nil {
log.Fatal(err)
}
if appConf.OnlyMigrate {
log.Println("migration finished")
return
}
if appConf.InsertMockData {
if appConf.IsProduction {
log.Fatal("cannot specify both `production` and `insert-mock-data`")
}
if err := mockdata.InsertSampleDataToDB(db); err != nil {
log.Fatal(err)
}
}
api, err := injectIntoAPIServer(appConf, db)
if err != nil {
log.Fatal(err)
}
e := echo.New()
if err := handler.Setup(appConf.IsProduction, e, api, handler.WithRequestLogger()); err != nil {
log.Fatal(err)
}
// Start server
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", appConf.Port)))
}