15652: Eliminate a malloc when writing a one-segment block.
[arvados.git] / sdk / go / auth / handlers.go
index ad1fa5141a1cf268729e33bdef3cacc3fb14d76c..b638f7982516b431e15322adde0b55b0637c8a3f 100644 (file)
@@ -9,17 +9,15 @@ import (
        "net/http"
 )
 
-type contextKey string
-
-var contextKeyCredentials contextKey = "credentials"
+type contextKeyCredentials struct{}
 
 // LoadToken wraps the next handler, adding credentials to the request
 // context so subsequent handlers can access them efficiently via
 // CredentialsFromRequest.
 func LoadToken(next http.Handler) http.Handler {
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-               if _, ok := r.Context().Value(contextKeyCredentials).(*Credentials); !ok {
-                       r = r.WithContext(context.WithValue(r.Context(), contextKeyCredentials, CredentialsFromRequest(r)))
+               if _, ok := r.Context().Value(contextKeyCredentials{}).(*Credentials); !ok {
+                       r = r.WithContext(context.WithValue(r.Context(), contextKeyCredentials{}, CredentialsFromRequest(r)))
                }
                next.ServeHTTP(w, r)
        })