Refactor routing and middleware architecture
This commit is contained in:
parent
08d41b0348
commit
fb97ba20c0
5 changed files with 62 additions and 51 deletions
14
main.go
14
main.go
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue