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

View File

@@ -2,6 +2,7 @@ package http
import (
"github.com/asim/go-micro/v3"
chimiddleware "github.com/go-chi/chi/middleware"
graphMiddleware "github.com/owncloud/ocis/graph/pkg/middleware"
svc "github.com/owncloud/ocis/graph/pkg/service/v0"
"github.com/owncloud/ocis/graph/pkg/version"
@@ -28,7 +29,7 @@ func Server(opts ...Option) (http.Service, error) {
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.Middleware(
middleware.RequestID,
chimiddleware.RequestID,
middleware.Version(
"graph",
version.String,

View File

@@ -4,8 +4,8 @@ import (
"net/http"
"time"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/render"
"github.com/ascarter/requestid"
msgraph "github.com/owncloud/open-graph-api-go"
)
@@ -72,13 +72,12 @@ func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, ms
"date": time.Now().UTC().Format(time.RFC3339),
// TODO return client-request-id?
}
if id, ok := requestid.FromContext(r.Context()); ok {
innererror["request-id"] = id
}
innererror["request-id"] = middleware.GetReqID(r.Context())
resp := &msgraph.OdataError{
Error: msgraph.OdataErrorMain{
Code: e.String(),
Message: msg,
Code: e.String(),
Message: msg,
Innererror: &innererror,
},
}