context: remove definition of Context

Back in the before time, the best practices surrounding usage of Context
weren't quite worked out. We defined our own type to make usage easier.
As this packaged was used elsewhere, it make it more and more
challenging to integrate with the forked `Context` type. Now that it is
available in the standard library, we can just use that one directly.

To make usage more consistent, we now use `dcontext` when referring to
the distribution context package.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-08-11 15:31:16 -07:00
parent 7a8efe719e
commit 9c88801a12
No known key found for this signature in database
GPG key ID: 67B3DED84EDC823F
90 changed files with 396 additions and 373 deletions

View file

@ -1,11 +1,12 @@
package handlers
import (
"context"
"errors"
"io"
"net/http"
ctxu "github.com/docker/distribution/context"
dcontext "github.com/docker/distribution/context"
)
// closeResources closes all the provided resources after running the target
@ -24,13 +25,13 @@ func closeResources(handler http.Handler, closers ...io.Closer) http.Handler {
// upload, it avoids sending a 400 error to keep the logs cleaner.
//
// The copy will be limited to `limit` bytes, if limit is greater than zero.
func copyFullPayload(responseWriter http.ResponseWriter, r *http.Request, destWriter io.Writer, limit int64, context ctxu.Context, action string) error {
func copyFullPayload(ctx context.Context, responseWriter http.ResponseWriter, r *http.Request, destWriter io.Writer, limit int64, action string) error {
// Get a channel that tells us if the client disconnects
var clientClosed <-chan bool
if notifier, ok := responseWriter.(http.CloseNotifier); ok {
clientClosed = notifier.CloseNotify()
} else {
ctxu.GetLogger(context).Warnf("the ResponseWriter does not implement CloseNotifier (type: %T)", responseWriter)
dcontext.GetLogger(ctx).Warnf("the ResponseWriter does not implement CloseNotifier (type: %T)", responseWriter)
}
var body = r.Body
@ -52,7 +53,7 @@ func copyFullPayload(responseWriter http.ResponseWriter, r *http.Request, destWr
// instead of showing 0 for the HTTP status.
responseWriter.WriteHeader(499)
ctxu.GetLoggerWithFields(context, map[interface{}]interface{}{
dcontext.GetLoggerWithFields(ctx, map[interface{}]interface{}{
"error": err,
"copied": copied,
"contentLength": r.ContentLength,
@ -63,7 +64,7 @@ func copyFullPayload(responseWriter http.ResponseWriter, r *http.Request, destWr
}
if err != nil {
ctxu.GetLogger(context).Errorf("unknown error reading request payload: %v", err)
dcontext.GetLogger(ctx).Errorf("unknown error reading request payload: %v", err)
return err
}