diff --git a/go.mod b/go.mod index b7fa4fbe..0eb03043 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/Jguer/go-alpm v0.0.0-20191122171459-5cffc6e8fc69 github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f github.com/Morganamilo/go-srcinfo v1.0.0 - github.com/mikkeloscar/aur v0.0.0-20191216074712-ebecb34b95b4 + github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656 ) go 1.13 diff --git a/go.sum b/go.sum index 734a2974..d11e95f4 100644 --- a/go.sum +++ b/go.sum @@ -4,5 +4,5 @@ github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f h1:ptFKy github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc= github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI= github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY= -github.com/mikkeloscar/aur v0.0.0-20191216074712-ebecb34b95b4 h1:qPyKOVOjHT0dJOS3FFYQzXTOa9gyDOL7CnjCWltkYtM= -github.com/mikkeloscar/aur v0.0.0-20191216074712-ebecb34b95b4/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA= +github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656 h1:j679+jxcDkCFblYk+I+G71HQTFxM3PacYbVCiYmhRhU= +github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA= diff --git a/vendor/github.com/mikkeloscar/aur/aur.go b/vendor/github.com/mikkeloscar/aur/aur.go index 7feb3885..d561d235 100644 --- a/vendor/github.com/mikkeloscar/aur/aur.go +++ b/vendor/github.com/mikkeloscar/aur/aur.go @@ -10,6 +10,11 @@ import ( //AURURL is the base string from which the query is built var AURURL = "https://aur.archlinux.org/rpc.php?" +var ( + // ErrServiceUnavailable represents a error when AUR is unavailable + ErrServiceUnavailable = errors.New("AUR is unavailable at this moment") +) + type response struct { Error string `json:"error"` Version int `json:"version"` @@ -22,7 +27,7 @@ type response struct { type By int const ( - Name By = iota + Name By = iota + 1 NameDesc Maintainer Depends @@ -86,13 +91,12 @@ func get(values url.Values) ([]Pkg, error) { if err != nil { return nil, err } - - if resp.StatusCode == http.StatusServiceUnavailable { - return nil, errors.New("AUR is unavailable at this moment") - } - defer resp.Body.Close() + if err := getErrorByStatusCode(resp.StatusCode); err != nil { + return nil, err + } + dec := json.NewDecoder(resp.Body) result := new(response) err = dec.Decode(result) @@ -119,6 +123,16 @@ func searchBy(query, by string) ([]Pkg, error) { return get(v) } +func getErrorByStatusCode(code int) error { + switch code { + case http.StatusBadGateway, http.StatusGatewayTimeout: + return ErrServiceUnavailable + case http.StatusServiceUnavailable: + return ErrServiceUnavailable + } + return nil +} + // Search searches for packages using the RPC's default search by. // This is the same as using SearchBy With NameDesc func Search(query string) ([]Pkg, error) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 2e4c9ab8..0b703853 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,9 +1,9 @@ -# github.com/Jguer/go-alpm v0.0.0-20191021114528-e11e8a60f385 +# github.com/Jguer/go-alpm v0.0.0-20191122171459-5cffc6e8fc69 github.com/Jguer/go-alpm # github.com/Morganamilo/go-pacmanconf v0.0.0-20180910220353-9c5265e1b14f github.com/Morganamilo/go-pacmanconf github.com/Morganamilo/go-pacmanconf/ini # github.com/Morganamilo/go-srcinfo v1.0.0 github.com/Morganamilo/go-srcinfo -# github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525 +# github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656 github.com/mikkeloscar/aur