-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (30 loc) · 926 Bytes
/
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
package main
import (
"log"
"net/http"
"subproblem/rest-api/pkg/controller"
"subproblem/rest-api/pkg/db"
"subproblem/rest-api/pkg/service"
"github.com/gorilla/mux"
"subproblem/rest-api/pkg/util"
)
func main() {
db, err := db.NewPostgresDb()
if err != nil {
log.Fatal(err)
}
if err := db.Init(); err != nil {
log.Fatal(err)
}
util.LoadEnv()
userService := service.NewUserService(db)
authService := service.NewAuthService(db)
userController := controller.NewUserController(userService)
authController := controller.NewAuthController(authService)
r := mux.NewRouter()
r.HandleFunc("/api/v1/register", authController.Register).Methods("POST")
r.HandleFunc("/api/v1/login", authController.Login).Methods("POST")
// Secured Endpoints
r.HandleFunc("/api/v1/user/{id}", authController.Middleware(http.HandlerFunc(userController.GetUserById))).Methods("GET")
http.ListenAndServe(":8080", r)
}