Use alice to chain middleware

This commit is contained in:
Jan Dittberner 2022-05-22 12:23:42 +02:00
parent 2ddc013c84
commit 44a6180a09
3 changed files with 10 additions and 2 deletions

View file

@ -21,6 +21,7 @@ import (
"io/fs"
"net/http"
"github.com/justinas/alice"
"github.com/vearutop/statigz"
"github.com/vearutop/statigz/brotli"
@ -45,5 +46,7 @@ func (app *application) routes() http.Handler {
mux.HandleFunc("/", app.home)
mux.HandleFunc("/motions/", app.motionList)
return app.recoverPanic(app.logRequest(secureHeaders(mux)))
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
return standard.Then(mux)
}

5
go.mod
View file

@ -25,7 +25,10 @@ require (
gopkg.in/yaml.v2 v2.4.0
)
require github.com/stretchr/testify v1.7.0
require (
github.com/justinas/alice v1.2.0
github.com/stretchr/testify v1.7.0
)
require (
github.com/Masterminds/goutils v1.1.1 // indirect

2
go.sum
View file

@ -752,6 +752,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v2.3.0+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=