-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (61 loc) · 1.77 KB
/
main.go
File metadata and controls
74 lines (61 loc) · 1.77 KB
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
72
73
74
package main
import (
"fmt"
"game-app-go/config"
"game-app-go/delivery/httpserver"
"game-app-go/repository/mysql"
"game-app-go/service/authservice"
"game-app-go/service/userservice"
"game-app-go/validator/uservalidator"
"time"
)
const (
JWTSignKey = "jwt_secret"
AccessTokenSubject = "at"
RefreshTokenSubject = "rt"
AccessTokenExpirationDuration = time.Hour * 24
RefreshTokenExpirationDuration = time.Hour * 24 * 7
)
func main(){
// 1- Load default config
// 2- read file and merge (override)
// 3- read env and merge (override)
cfg2 := config.Load()
fmt.Println(cfg2)
cfg := config.Config{
HTTPServer: config.HTTPServer{Port: 8080},
Auth: authservice.Config{
SignKey: JWTSignKey,
AccessExpirationTime: AccessTokenExpirationDuration,
RefresExpirationTime: RefreshTokenExpirationDuration,
AccessSubject: AccessTokenSubject,
RefreshSubject: RefreshTokenSubject,
},
Mysql: mysql.Config{
Username: "gameapp",
Password: "gameapp",
Port: 3308,
Host: "localhost",
DBName: "gameapp_db",
},
}
// TODO: add command for up, down and status
// mgr :=migrator.New(cfg.Mysql)
// mgr.Up()
authSvc, userSvc, userValidator := setupServices(cfg)
server := httpserver.New(cfg, authSvc, userSvc, userValidator)
fmt.Println("Start Echo server")
server.Serve()
// http.HandleFunc("/user/login", userLoginHandler)
// http.HandleFunc("/user/profile", userProfileHandler)
// log.Print("serever is running on port 8080")
// http.ListenAndServe(":8080", nil)
}
func setupServices(cfg config.Config)(authservice.Service, userservice.Service,
uservalidator.Validator){
authSvc := authservice.New(cfg.Auth)
MysqlRepo := mysql.New(cfg.Mysql)
userSvc := userservice.New(authSvc, MysqlRepo)
uV := uservalidator.New(MysqlRepo)
return authSvc, userSvc, uV
}