45 lines
963 B
Go
45 lines
963 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/notes/views"
|
|
)
|
|
|
|
func main() {
|
|
var confFile string
|
|
|
|
flag.StringVar(&confFile, "c", "/etc/gonotes/conf.toml", "Specify path to config file.")
|
|
flag.Parse()
|
|
|
|
conf.LoadConfig(confFile)
|
|
|
|
router := http.NewServeMux()
|
|
notesRouter := views.GetRoutes("/notes")
|
|
|
|
router.Handle("/", http.RedirectHandler("/notes/", http.StatusFound))
|
|
router.Handle("/notes/", http.StripPrefix("/notes", notesRouter))
|
|
router.Handle(
|
|
"/static/",
|
|
logger(
|
|
http.FileServer(http.FS(conf.Static)),
|
|
),
|
|
)
|
|
|
|
listener, err := net.Listen(conf.Conf.Protocol, conf.Conf.Address)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Fatal(http.Serve(listener, 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)
|
|
})
|
|
}
|