packageclientimport("encoding/json""net/http""net/url""github.com/docker/docker/api/types""github.com/docker/docker/api/types/registry""golang.org/x/net/context")// RegistryLogin authenticates the docker server with a given docker registry.// It returns unauthorizedError when the authentication fails.func(cli*Client)RegistryLogin(ctxcontext.Context,authtypes.AuthConfig)(registry.AuthenticateOKBody,error){resp,err:=cli.post(ctx,"/auth",url.Values{},auth,nil)ifresp.statusCode==http.StatusUnauthorized{returnregistry.AuthenticateOKBody{},unauthorizedError{err}}iferr!=nil{returnregistry.AuthenticateOKBody{},err}varresponseregistry.AuthenticateOKBodyerr=json.NewDecoder(resp.body).Decode(&response)ensureReaderClosed(resp)returnresponse,err}