-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
70 lines (52 loc) · 2.08 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Hello Neighbour
*
* This is the API for the 'Hello Neighbour' project inspired from the COVID-19 Global Church Hack
*
* API version: 0.0.3
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package main
import (
"flag"
"net/http"
"github.com/jsfan/hello-neighbour-api/internal/config"
"github.com/jsfan/hello-neighbour-api/internal/middlewares"
"github.com/jsfan/hello-neighbour-api/internal/storage"
"github.com/jsfan/hello-neighbour-api/internal/rest/common"
"github.com/jsfan/hello-neighbour-api/internal/rest/service"
"github.com/golang/glog"
rest "github.com/jsfan/hello-neighbour-api/internal/rest"
)
func main() {
cfgFileOpt := flag.String("config", "config.yaml", "Configuration YAML file")
flag.Parse()
cfg, err := config.ReadConfig(*cfgFileOpt)
if err != nil {
glog.Fatalf(`Could not read configuration file "%s": %v`, *cfgFileOpt, err)
}
jwtKeys, err := config.ReadKeyPair(&cfg.JwtSignKeys)
if err != nil {
glog.Fatalf(`Could not load key pair: %v`, err)
}
con, err := storage.Connect(&cfg.Database)
if err != nil {
glog.Fatalf("Could not connect to database: %v", err)
}
if err := con.Migrate(&cfg.Database.DbName); err != nil && err.Error() != "no change" {
glog.Fatalf("Database migration failed: %v", err)
}
glog.Infof("Server started")
AdministratorApiService := service.NewAdministratorApiService()
AdministratorApiController := rest.NewAdministratorApiController(AdministratorApiService)
DefaultApiService := service.NewDefaultApiService()
DefaultApiController := rest.NewDefaultApiController(DefaultApiService)
LeaderApiService := service.NewLeaderApiService()
LeaderApiController := rest.NewLeaderApiController(LeaderApiService)
MemberApiService := service.NewMemberApiService()
MemberApiController := rest.NewMemberApiController(MemberApiService)
router := common.NewRouter(jwtKeys, AdministratorApiController, DefaultApiController, LeaderApiController, MemberApiController)
router.Use(middlewares.StorageMiddleWare(con))
router.Use(middlewares.AuthzMiddleware(con))
glog.Fatal(http.ListenAndServe(":8080", router))
}