-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
30 lines (25 loc) · 813 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
package main
import (
"log"
"net/http"
"os"
"github.com/t0w4/toDoListBackend/db"
"github.com/gorilla/mux"
"github.com/t0w4/toDoListBackend/controller"
)
func main() {
dbConn, err := db.Init()
if err != nil {
log.Printf("db init failed: %v", err)
os.Exit(1)
}
tc := &controller.TaskController{dbConn}
router := mux.NewRouter()
router.HandleFunc("/tasks", tc.CreateTask).Methods(http.MethodPost, http.MethodOptions)
router.HandleFunc("/tasks", tc.GetTasks).Methods(http.MethodGet)
router.HandleFunc("/tasks/{uuid}", tc.GetTask).Methods(http.MethodGet)
router.HandleFunc("/tasks/{uuid}", tc.PutTask).Methods(http.MethodPut)
router.HandleFunc("/tasks/{uuid}", tc.DeleteTask).Methods(http.MethodDelete, http.MethodOptions)
log.Print(http.ListenAndServe("0.0.0.0:8080", router))
os.Exit(1)
}