-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (32 loc) · 1.01 KB
/
main.go
File metadata and controls
38 lines (32 loc) · 1.01 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
package main
import (
"book_seller/domain"
"book_seller/handlers"
"book_seller/middleware"
"database/sql"
"fmt"
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
)
func main() {
var db *sql.DB
postgresConnectionString := "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable"
postgresConnectionString = fmt.Sprintf(postgresConnectionString, "localhost", "5432", "postgres", "lolpro123", "books")
db, err := sql.Open("postgres", postgresConnectionString)
if err != nil {
panic(err)
}
defer db.Close()
userService := domain.NewDomainDB(db)
userHandler := handlers.NewUserHandler(userService)
r := gin.Default()
r.POST("/login", userHandler.LoginHandler)
auth := r.Group("/")
auth.Use(middleware.AuthMiddleware())
auth.POST("/users", userHandler.CreateUserHandler)
auth.GET("/users", userHandler.GetUsersHandler)
auth.GET("/users/:id", userHandler.GetUserHandler)
auth.PUT("/users/:id", userHandler.UpdateUserHandler)
auth.DELETE("/users/:id", userHandler.DeleteUserHandler)
r.Run(":8080")
}