2025-01-26 22:23:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2025-02-04 20:27:32 +00:00
|
|
|
"fmt"
|
2025-01-26 22:23:42 +00:00
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"gitea.gwairfelin.com/max/gonotes/internal/conf"
|
|
|
|
|
"gitea.gwairfelin.com/max/gonotes/internal/notes/views"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
conf.LoadConfig("./conf.toml")
|
|
|
|
|
|
|
|
|
|
router := http.NewServeMux()
|
|
|
|
|
notesRouter := views.GetRoutes("/notes")
|
|
|
|
|
|
|
|
|
|
router.Handle("/notes/", http.StripPrefix("/notes", notesRouter))
|
2025-01-28 22:08:01 +00:00
|
|
|
router.Handle(
|
|
|
|
|
conf.Conf.Static.Root,
|
|
|
|
|
logger(
|
|
|
|
|
http.StripPrefix(
|
|
|
|
|
"/static",
|
|
|
|
|
http.FileServer(http.Dir(conf.Conf.Static.Dir)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
2025-02-04 20:27:32 +00:00
|
|
|
addr := fmt.Sprintf(":%d", conf.Conf.Port)
|
|
|
|
|
log.Fatal(http.ListenAndServe(addr, router))
|
2025-01-26 22:23:42 +00:00
|
|
|
}
|
2025-01-28 22:08:01 +00:00
|
|
|
|
|
|
|
|
func logger(next http.Handler) http.Handler {
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
log.Print(r.URL.Path)
|
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
|
})
|
|
|
|
|
}
|