gonotes/cmd/server/main.go

35 lines
717 B
Go

package main
import (
"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))
router.Handle(
conf.Conf.Static.Root,
logger(
http.StripPrefix(
"/static",
http.FileServer(http.Dir(conf.Conf.Static.Dir)),
),
),
)
log.Fatal(http.ListenAndServe(":8080", router))
}
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)
})
}