-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (55 loc) · 2.01 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
71
package main
import (
"log"
"net/http"
"os"
"github.com/go-qiu/rrs-web-server/pkg/application"
"github.com/go-qiu/rrs-web-server/pkg/controllers"
"github.com/joho/godotenv"
)
func main() {
// get .env values
err := godotenv.Load()
if err != nil {
// fail
errString := "[RRS]: fail to load .env"
log.Fatal(errString)
}
SERVER_ADDR := os.Getenv("SERVER_ADDR")
// API_KEY_USERS := os.Getenv("API_KEY_USERS")
// API_KEY_VOUCHERS := os.Getenv("API_KEY_VOUCHERS")
// API_KEY_MERCHANTS := os.Getenv("API_KEY_MERCHANTS")
// set the custom router.
// router := routers.New()
jwtConfig := controllers.JWTConfig{
ISSUER: os.Getenv("JWT_ISSUER"),
EXP_MIN: os.Getenv("JWT_EXP_MINUTES"),
SECRET_KEY: os.Getenv("JWT_SECRET_KEY"),
}
// instantiate an in-memory data store, to cache the Users data points.
// var dsUsers ds.DataStore = *ds.New()
// instantiate an application to link the respective controllers and router.
app := application.New()
app.DataStore = make(map[string]controllers.DataPointExtended)
// populate the users in-memory cache, using the users data from users microservice.
app.PullDataIntoDataStore()
// instantiate a authentication controller.
authCtl := controllers.NewAuthCtl("JWT AUTH SERVICE", "", &jwtConfig, app.DataStore)
app.Controllers.Auth = authCtl
// instantiate a voucher controller.
app.Controllers.CRUD.Vouchers = controllers.NewVouchersCtl("VOUCHERS", "", app.DataStore)
// instantiate a merchant controller.
app.Controllers.CRUD.Merchants = controllers.NewMerchantCtl("MERCHANTS", "", app.DataStore)
// instantiate a transaction controller.
app.Controllers.CRUD.Transactions = controllers.NewTransactionCtl("TRANSACTIONS", "", nil)
// app.Router = router
// instantiate a custom http server.
srv := http.Server{
Addr: SERVER_ADDR,
Handler: app.Router(),
}
// start http server.
log.Printf("HTTPS Server started and listening on https://%s ...\n", SERVER_ADDR)
log.Fatalln(srv.ListenAndServeTLS("./ssl/localhost.cert.pem", "./ssl/localhost.key.pem"))
//
}