forked from Rarik88/go_final_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainHandle.go
More file actions
39 lines (32 loc) · 853 Bytes
/
mainHandle.go
File metadata and controls
39 lines (32 loc) · 853 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
39
package main
import (
"github.com/go-chi/chi/v5"
"go_final_project/db"
"go_final_project/handlers"
"log"
"net/http"
"os"
)
const DefaultPort = "7540"
func main() {
db.SetupDb()
webDir := "web"
port, exists := os.LookupEnv("PORT")
if !exists {
log.Println("No PORT number provided... Setting to default")
port = DefaultPort
}
r := chi.NewRouter()
r.Handle("/*", http.StripPrefix("/", http.FileServer(http.Dir(webDir))))
r.Get("/api/nextdate", handlers.HandleNextDate)
r.Get("/api/tasks", handlers.HandleGetTasks)
r.Get("/api/task", handlers.HandleGetTaskById)
r.Post("/api/task", handlers.HandlePostTask)
r.Post("/api/task/done", handlers.HandleTaskDone)
r.Put("/api/task", handlers.HandlePutTask)
r.Delete("/api/task", handlers.HandleDeleteTask)
err := http.ListenAndServe(":"+port, r)
if err != nil {
panic(err)
}
}