fix golint errors

This commit is contained in:
Wenkai Yin 2016-05-13 15:37:12 +08:00
parent d2ba4f7c40
commit 3ff3128921
3 changed files with 22 additions and 21 deletions

View File

@ -89,7 +89,7 @@ func (r *Registry) Catalog() ([]string, error) {
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return repos, e
}

View File

@ -111,14 +111,15 @@ func NewRepositoryWithUsername(name, endpoint, username string) (*Repository, er
return repository, nil
}
func isUnauthorizedError(err error) (error, bool) {
// try to convert err to errors.Error if it is
func isUnauthorizedError(err error) (bool, error) {
if strings.Contains(err.Error(), http.StatusText(http.StatusUnauthorized)) {
return errors.Error{
return true, errors.Error{
StatusCode: http.StatusUnauthorized,
StatusText: http.StatusText(http.StatusUnauthorized),
}, true
}
}
return err, false
return false, err
}
// ListTag ...
@ -131,7 +132,7 @@ func (r *Repository) ListTag() ([]string, error) {
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return tags, e
}
@ -178,7 +179,7 @@ func (r *Repository) ManifestExist(reference string) (digest string, exist bool,
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
err = e
return
@ -224,7 +225,7 @@ func (r *Repository) PullManifest(reference string, acceptMediaTypes []string) (
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
err = e
return
@ -265,7 +266,7 @@ func (r *Repository) PushManifest(reference, mediaType string, payload []byte) (
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
err = e
return
@ -303,7 +304,7 @@ func (r *Repository) DeleteManifest(digest string) error {
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return e
}
@ -354,7 +355,7 @@ func (r *Repository) BlobExist(digest string) (bool, error) {
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return false, e
}
@ -392,7 +393,7 @@ func (r *Repository) PullBlob(digest string) (size int64, data []byte, err error
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
err = e
return
@ -431,7 +432,7 @@ func (r *Repository) initiateBlobUpload(name string) (location, uploadUUID strin
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
err = e
return
@ -469,7 +470,7 @@ func (r *Repository) monolithicBlobUpload(location, digest string, size int64, d
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return e
}
@ -523,7 +524,7 @@ func (r *Repository) DeleteBlob(digest string) error {
resp, err := r.client.Do(req)
if err != nil {
e, ok := isUnauthorizedError(err)
ok, e := isUnauthorizedError(err)
if ok {
return e
}

View File

@ -31,12 +31,12 @@ import (
)
var (
username string = "user"
password string = "P@ssw0rd"
repo string = "samalba/my-app"
tags tagResp = tagResp{Tags: []string{"1.0", "2.0", "3.0"}}
validToken string = "valid_token"
invalidToken string = "invalid_token"
username = "user"
password = "P@ssw0rd"
repo = "samalba/my-app"
tags = tagResp{Tags: []string{"1.0", "2.0", "3.0"}}
validToken = "valid_token"
invalidToken = "invalid_token"
credential auth.Credential
registryServer *httptest.Server
tokenServer *httptest.Server