2024-03-15 18:34:24 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NotFound returns a user-friendly 404 error page
|
|
|
|
func NotFound(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(404)
|
|
|
|
http.ServeFile(w, r, "./pages/error/404.html")
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDay(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// TODO: This will be *very* different, `today` func will be needed
|
|
|
|
dayString := chi.URLParam(r, "day")
|
|
|
|
if dayString == "" {
|
2024-03-15 20:20:33 +03:00
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
w.Write([]byte("day not specified"))
|
|
|
|
return
|
2024-03-15 18:34:24 +03:00
|
|
|
}
|
|
|
|
GetFile("day/"+dayString, w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetNote(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// TODO: This will be *very* different, `today` func will be needed
|
|
|
|
noteString := chi.URLParam(r, "note")
|
|
|
|
if noteString == "" {
|
2024-03-15 20:20:33 +03:00
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
w.Write([]byte("note not specified"))
|
2024-03-15 18:34:24 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
GetFile("notes/"+noteString, w, r)
|
|
|
|
}
|
|
|
|
|
2024-03-15 20:20:33 +03:00
|
|
|
func GetToday(w http.ResponseWriter, r *http.Request) {
|
|
|
|
GetFile("day/"+time.Now().Format("2006-01-02"), w, r)
|
|
|
|
}
|
2024-03-15 18:34:24 +03:00
|
|
|
|
2024-03-15 20:20:33 +03:00
|
|
|
func PostToday(w http.ResponseWriter, r *http.Request) {
|
|
|
|
PostFile("day/"+time.Now().Format("2006-01-02"), w, r)
|
2024-03-15 18:34:24 +03:00
|
|
|
}
|