-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (38 loc) · 1.13 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
package main
import (
"flag"
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/mcornut/go-rest-api/controllers"
"github.com/mcornut/go-rest-api/routes"
"github.com/mcornut/go-rest-api/utils/database"
)
//go:generate mockery -name DocumentController -dir ./controllers
//go:generate mockery -name DocumentRepository -dir ./repositories
func formatLog() {
Formatter := new(log.TextFormatter)
Formatter.TimestampFormat = "02-01-2006 15:04:05"
Formatter.FullTimestamp = true
log.SetFormatter(Formatter)
}
func main() {
formatLog()
configPath := flag.String("config", "local.toml", "config path")
flag.Parse()
config, err := ConfigFromFile(*configPath)
if err != nil {
log.Fatal(err)
}
db, err := database.Connect(config.DB.Username, config.DB.Password, config.DB.Name, config.DB.Host, config.DB.Port)
if err != nil {
log.Fatal(err)
}
documentController := controllers.NewDocumentController(db)
mux := http.NewServeMux()
routes.CreateRoutes(mux, documentController)
addr := "localhost:8080"
log.Infof("Server listening on %s", addr)
if err := http.ListenAndServe(addr, mux); err != nil {
log.Fatal(err)
}
}