gonotes/cmd/server/main.go

40 lines
824 B
Go
Raw Normal View History

package main
import (
2025-02-04 20:27:32 +00:00
"fmt"
"log"
"net/http"
2025-06-01 21:27:08 +01:00
"os"
2025-06-01 21:27:08 +01:00
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
"forgejo.gwairfelin.com/max/gonotes/internal/notes/views"
)
func main() {
2025-06-01 21:27:08 +01:00
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))
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-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)
})
}