Tiny refactor

It is a little wired to use "err.ServeHTTP". Via the sample from
docker/distribution, we can use "challenge" as the variable name here.

Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
HuKeping 2016-03-29 21:18:07 +08:00
parent 7be7b6beb5
commit 39c3f46006
1 changed files with 4 additions and 2 deletions

View File

@ -64,8 +64,10 @@ func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var authCtx context.Context
var err error
if authCtx, err = root.auth.Authorized(ctx, access...); err != nil {
if err, ok := err.(auth.Challenge); ok {
err.ServeHTTP(w, r)
if challenge, ok := err.(auth.Challenge); ok {
// Let the challenge write the response.
challenge.ServeHTTP(w, r)
w.WriteHeader(http.StatusUnauthorized)
return
}