-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
32 lines (28 loc) · 837 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
package main
import (
"net/http"
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/gorilla/mux"
"github.com/msound/todo/pkg/db"
"github.com/msound/todo/pkg/handler"
"github.com/msound/todo/pkg/view"
)
func main() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Info().Msg("Starting TODO")
view.Load()
dbClient, err := db.NewClient(os.Getenv("MONGODB_URI"))
if err != nil {
panic("Database connection failed: " + err.Error())
}
app := handler.NewApp(dbClient)
r := mux.NewRouter()
r.HandleFunc("/", app.IndexHandler).Methods("GET")
r.HandleFunc("/task/{id}/done", app.TaskDoneHandler).Methods("POST")
r.HandleFunc("/task/{id}/undo", app.TaskUndoHandler).Methods("POST")
r.HandleFunc("/task", app.AddTaskHandler).Methods("POST")
exit := http.ListenAndServe(":80", r)
log.Fatal().Err(exit)
}