-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 846 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
43
44
45
46
47
48
49
package main
import (
"log"
"api-boilerplate/config"
"api-boilerplate/database"
"api-boilerplate/models/domain"
"api-boilerplate/server"
)
type Main struct {
Config domain.Cfg
DB *database.DB
HTTPServer *server.Server
}
// NewMain returns a new instance of Main.
func NewMain() *Main {
cfg := config.InitConfig()
db, err := database.NewDB(cfg, "database/migrations")
if err != nil {
log.Fatal(err)
}
return &Main{
Config: cfg,
DB: db,
HTTPServer: server.InitServer(),
}
}
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
m := NewMain()
m.Run()
}
func (m *Main) Run() {
m.HTTPServer.UserService = database.NewUserService(m.DB)
log.Println("Server started on port " + m.Config.Server.Port)
err := m.HTTPServer.StartServer(":" + m.Config.Server.Port)
if err != nil {
log.Fatal(err)
}
}