-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
58 lines (50 loc) · 1.3 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
package main
import (
"Shopee_UMS/api"
database "Shopee_UMS/db"
"Shopee_UMS/entities"
"Shopee_UMS/reposistory"
"Shopee_UMS/storage"
"Shopee_UMS/usecases"
"Shopee_UMS/utils"
"log"
"net/http"
_ "net/http/pprof"
"strconv"
)
func main() {
go func() {
log.Println(http.ListenAndServe(":6060", nil))
}()
db, err := database.NewMySQL(10, 10)
if err != nil {
log.Fatal("could not connect to DB", err)
}
s3, err := storage.NewS3()
if err != nil {
log.Fatal("could not connect to AWS S3", err)
}
rdb, err := database.NewRedis()
if err != nil {
log.Fatal("could not connect to Redis", err)
}
accounts := reposistory.NewAccounts(db, rdb)
users := reposistory.NewUsers(db, rdb)
statics := reposistory.NewStatics(s3)
u := usecases.New(accounts, users, statics)
auth := newJwtAuthenticator()
s := api.NewServer(u, auth)
log.Println("start listening on port 8000")
log.Fatal(http.ListenAndServe(":8000", s))
}
func newJwtAuthenticator() *entities.JwtAuthenticator {
privateKey := utils.ReadRSAPrivateKey("./jwtRS256.key")
publicKey := utils.ReadRSAPublicKey("./jwtRS256.key.pub")
expSec, _ := strconv.Atoi(utils.MustEnv("AUTH_TOKEN_EXPIRATION_SECONDS"))
return &entities.JwtAuthenticator{
PrivateKey: privateKey,
PublicKey: publicKey,
ExpSeconds: expSec,
Issuer: "Shopee UMS",
}
}