Refactor routing and middleware architecture

This commit is contained in:
bronku 2025-03-22 11:22:45 +01:00
parent 08d41b0348
commit fb97ba20c0
5 changed files with 62 additions and 51 deletions

14
main.go
View file

@ -5,7 +5,7 @@ import (
"net/http"
"github.com/Bronku/iroon/auth"
"github.com/Bronku/iroon/middleware"
"github.com/Bronku/iroon/logging"
"github.com/Bronku/iroon/router"
)
@ -16,12 +16,8 @@ func main() {
}
defer h.Close()
var a auth.Authenticator
a = auth.New()
// #todo: make handler functions private, and create a servemux in router
http.HandleFunc("GET /order/", middleware.Logger(a.Authenticate(h.Form)))
http.HandleFunc("GET /", middleware.Logger(a.Authenticate(h.Index)))
http.HandleFunc("POST /", middleware.Logger(a.Authenticate(h.AddOrder)))
http.ListenAndServe(":8080", nil)
var handler http.Handler = h
handler = logging.Middleware(handler)
handler = auth.New().Middleware(handler)
log.Fatal(http.ListenAndServe(":8080", handler))
}