Browse Source

Golint: don't use basic untyped string for context key

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 7 years ago
parent
commit
dfac74a9e4
2 changed files with 5 additions and 3 deletions
  1. 3 1
      api/server/httputils/httputils.go
  2. 2 2
      api/server/middleware/version.go

+ 3 - 1
api/server/httputils/httputils.go

@@ -11,8 +11,10 @@ import (
 	"golang.org/x/net/context"
 )
 
+type contextKey string
+
 // APIVersionKey is the client's requested API version.
-const APIVersionKey = "api-version"
+const APIVersionKey contextKey = "api-version"
 
 // APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
 // Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion).

+ 2 - 2
api/server/middleware/version.go

@@ -5,6 +5,7 @@ import (
 	"net/http"
 	"runtime"
 
+	"github.com/docker/docker/api/server/httputils"
 	"github.com/docker/docker/api/types/versions"
 	"golang.org/x/net/context"
 )
@@ -57,8 +58,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
 		if versions.GreaterThan(apiVersion, v.defaultVersion) {
 			return versionUnsupportedError{version: apiVersion, maxVersion: v.defaultVersion}
 		}
-		// nolint: golint
-		ctx = context.WithValue(ctx, "api-version", apiVersion)
+		ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion)
 		return handler(ctx, w, r, vars)
 	}