-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
42 lines (33 loc) · 905 Bytes
/
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
package main
import (
"github.com/ras0q/go-backend-template/internal/handler"
"github.com/ras0q/go-backend-template/internal/migration"
"github.com/ras0q/go-backend-template/internal/pkg/config"
"github.com/ras0q/go-backend-template/internal/repository"
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
// middlewares
e.Use(middleware.Recover())
e.Use(middleware.Logger())
// connect to database
db, err := sqlx.Connect("mysql", config.MySQL().FormatDSN())
if err != nil {
e.Logger.Fatal(err)
}
defer db.Close()
// 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)
v1API := e.Group("/api/v1")
h.SetupRoutes(v1API)
e.Logger.Fatal(e.Start(config.AppAddr()))
}