-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (28 loc) · 652 Bytes
/
main.go
File metadata and controls
38 lines (28 loc) · 652 Bytes
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 (
"fmt"
"net/http"
"todos-api/dbconfig"
"todos-api/internal/auth"
"todos-api/internal/handlers"
"github.com/go-chi/chi/v5"
_ "github.com/lib/pq"
)
func main() {
dbconfig.ConfigDB()
r := chi.NewRouter()
r.Group(func(r chi.Router) {
r.Post("/login", handlers.Login)
r.Post("/user", handlers.CreateUser)
})
r.Group(func(r chi.Router) {
r.Use(auth.MyMiddleware)
r.Post("/", handlers.Create)
r.Put("/{id}", handlers.Update)
r.Delete("/{id}", handlers.Delete)
r.Get("/", handlers.List)
r.Get("/{id}", handlers.Get)
})
http.ListenAndServe(fmt.Sprintf(":%s", "8080"), r)
defer dbconfig.DB.Close()
}