2025-01-26 22:23:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2025-06-18 22:18:12 +01:00
|
|
|
"flag"
|
2025-01-26 22:23:42 +00:00
|
|
|
"log"
|
2025-06-17 22:06:56 +01:00
|
|
|
"net"
|
2025-01-26 22:23:42 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
2025-06-01 21:27:08 +01:00
|
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
|
|
|
|
|
"forgejo.gwairfelin.com/max/gonotes/internal/notes/views"
|
2025-01-26 22:23:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-06-18 22:18:12 +01:00
|
|
|
var confFile string
|
|
|
|
|
|
2025-06-24 19:48:55 +01:00
|
|
|
flag.StringVar(&confFile, "c", "/etc/gonotes/conf.toml", "Specify path to config file.")
|
2025-06-18 22:18:12 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
conf.LoadConfig(confFile)
|
2025-01-26 22:23:42 +00:00
|
|
|
|
|
|
|
|
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-06-17 22:06:56 +01:00
|
|
|
|
|
|
|
|
listener, err := net.Listen(conf.Conf.Protocol, conf.Conf.Address)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
log.Fatal(http.Serve(listener, 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)
|
|
|
|
|
})
|
|
|
|
|
}
|