39 lines
824 B
Go
39 lines
824 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/notes/views"
|
|
)
|
|
|
|
func main() {
|
|
os.Mkdir("./foobardir", os.ModeDir|os.ModePerm)
|
|
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)),
|
|
),
|
|
),
|
|
)
|
|
addr := fmt.Sprintf(":%d", conf.Conf.Port)
|
|
log.Fatal(http.ListenAndServe(addr, 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)
|
|
})
|
|
}
|