use go-chi middlewares

go-chi already delivers the middlewares we need so we don't need to import other libraries for that.
This commit is contained in:
David Christofas
2021-08-12 17:14:41 +02:00
parent 2927dc45c3
commit 3bc60510ce
16 changed files with 37 additions and 66 deletions
-18
View File
@@ -1,18 +0,0 @@
package middleware
import (
"net/http"
"github.com/tomasen/realip"
)
// RealIP is a middleware that sets a http.Request RemoteAddr.
func RealIP(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if ip := realip.RealIP(r); ip != "" {
r.RemoteAddr = ip
}
next.ServeHTTP(w, r)
})
}
-12
View File
@@ -1,12 +0,0 @@
package middleware
import (
"net/http"
"github.com/ascarter/requestid"
)
// RequestID is a convenient middleware to inject a request id.
func RequestID(next http.Handler) http.Handler {
return requestid.RequestIDHandler(next)
}
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"net/http/pprof"
chimiddleware "github.com/go-chi/chi/middleware"
"github.com/justinas/alice"
"github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -47,8 +48,8 @@ func NewService(opts ...Option) *http.Server {
return &http.Server{
Addr: dopts.Address,
Handler: alice.New(
middleware.RealIP,
middleware.RequestID,
chimiddleware.RealIP,
chimiddleware.RequestID,
middleware.NoCache,
middleware.Cors,
middleware.Secure,