forked from ras0q/go-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (48 loc) · 1.24 KB
/
main.go
File metadata and controls
65 lines (48 loc) · 1.24 KB
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
57
58
59
60
61
62
63
64
65
package main
import (
"log"
"github.com/pikachu0310/go-backend-template/core"
"github.com/pikachu0310/go-backend-template/core/database"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/ras0q/goalie"
)
// @title Go Backend Template API
// @version 1.0
// @description バックエンドテンプレートのAPI仕様書です。
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url https://github.com/pikachu0310/go-backend-template
// @contact.email support@example.com
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
// @host localhost:8080
// @BasePath /api/v1
// @schemes http https
func main() {
if err := run(); err != nil {
log.Fatalf("runtime error: %+v", err)
}
}
func run() (err error) {
g := goalie.New()
defer g.Collect(&err)
var config core.Config
config.Parse()
e := echo.New()
// middlewares
e.Use(middleware.Recover())
e.Use(middleware.Logger())
// connect to and migrate database
db, err := database.Setup(config.MySQLConfig())
if err != nil {
return err
}
defer g.Guard(db.Close)
s := core.InjectDeps(db)
core.SetupRoutes(s.Handler, e)
if err := e.Start(config.AppAddr); err != nil {
return err
}
return nil
}