-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·47 lines (40 loc) · 1.27 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
package main
import (
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues"
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues/application"
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues/domain"
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues/persistence/db"
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues/web"
"github.com/Advanced-Go/Day-6/5-Authentication/easy-issues/web/handler"
"log"
"net/http"
"time"
)
func main() {
authRepo := db.NewAuthRepository()
authService := application.AuthService{
AuthRepository: authRepo,
}
authController := web.AuthController{
AuthService: authService,
Secret: application.Secret,
}
pwhash, _ := easy_issues.HashPassword("opensessame")
authRepo.Create(&domain.UserRegistration{
Email: "aladdin@mail.com",
Uuid: "1234",
PasswordHash: pwhash,
})
mux := http.NewServeMux()
mux.HandleFunc("/auth/login", authController.Login)
mux.HandleFunc("/auth/verify", handler.JWTAuthHandler(authController.Verify))
server := &http.Server{
Addr: ":8090",
Handler: mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(server.ListenAndServe())
}