mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
all: Apply staticcheck recommendations
This commit is contained in:
@@ -58,18 +58,18 @@ func (ns *Namespace) GetCSV(sep string, urlParts ...string) (d [][]string, err e
|
||||
url := strings.Join(urlParts, "")
|
||||
cache := ns.cacheGetCSV
|
||||
|
||||
unmarshal := func(b []byte) (error, bool) {
|
||||
unmarshal := func(b []byte) (bool, error) {
|
||||
if !bytes.Contains(b, []byte(sep)) {
|
||||
return _errors.Errorf("cannot find separator %s in CSV for %s", sep, url), false
|
||||
return false, _errors.Errorf("cannot find separator %s in CSV for %s", sep, url)
|
||||
}
|
||||
|
||||
if d, err = parseCSV(b, sep); err != nil {
|
||||
err = _errors.Wrapf(err, "failed to parse CSV file %s", url)
|
||||
|
||||
return err, true
|
||||
return true, err
|
||||
}
|
||||
|
||||
return nil, false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
var req *http.Request
|
||||
@@ -103,12 +103,12 @@ func (ns *Namespace) GetJSON(urlParts ...string) (interface{}, error) {
|
||||
return nil, _errors.Wrapf(err, "Failed to create request for getJSON resource %s", url)
|
||||
}
|
||||
|
||||
unmarshal := func(b []byte) (error, bool) {
|
||||
unmarshal := func(b []byte) (bool, error) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
if err != nil {
|
||||
return err, true
|
||||
return true, err
|
||||
}
|
||||
return nil, false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", "application/json")
|
||||
|
@@ -34,7 +34,7 @@ var (
|
||||
)
|
||||
|
||||
// getRemote loads the content of a remote file. This method is thread safe.
|
||||
func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (error, bool), req *http.Request) error {
|
||||
func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (bool, error), req *http.Request) error {
|
||||
url := req.URL.String()
|
||||
id := helpers.MD5String(url)
|
||||
var handled bool
|
||||
@@ -63,7 +63,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (e
|
||||
}
|
||||
res.Body.Close()
|
||||
|
||||
err, retry = unmarshal(b)
|
||||
retry, err = unmarshal(b)
|
||||
|
||||
if err == nil {
|
||||
// Return it so it can be cached.
|
||||
@@ -85,7 +85,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (e
|
||||
|
||||
if !handled {
|
||||
// This is cached content and should be correct.
|
||||
err, _ = unmarshal(b)
|
||||
_, err = unmarshal(b)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -104,14 +104,14 @@ func getLocal(url string, fs afero.Fs, cfg config.Provider) ([]byte, error) {
|
||||
|
||||
// getResource loads the content of a local or remote file and returns its content and the
|
||||
// cache ID used, if relevant.
|
||||
func (ns *Namespace) getResource(cache *filecache.Cache, unmarshal func(b []byte) (error, bool), req *http.Request) error {
|
||||
func (ns *Namespace) getResource(cache *filecache.Cache, unmarshal func(b []byte) (bool, error), req *http.Request) error {
|
||||
switch req.URL.Scheme {
|
||||
case "":
|
||||
b, err := getLocal(req.URL.String(), ns.deps.Fs.Source, ns.deps.Cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err, _ = unmarshal(b)
|
||||
_, err = unmarshal(b)
|
||||
return err
|
||||
default:
|
||||
return ns.getRemote(cache, unmarshal, req)
|
||||
|
@@ -114,9 +114,9 @@ func TestScpGetRemote(t *testing.T) {
|
||||
ns.client = cl
|
||||
|
||||
var c []byte
|
||||
f := func(b []byte) (error, bool) {
|
||||
f := func(b []byte) (bool, error) {
|
||||
c = b
|
||||
return nil, false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
err = ns.getRemote(cache, f, req)
|
||||
@@ -158,15 +158,15 @@ func TestScpGetRemoteParallel(t *testing.T) {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 10; j++ {
|
||||
var c []byte
|
||||
f := func(b []byte) (error, bool) {
|
||||
f := func(b []byte) (bool, error) {
|
||||
c = b
|
||||
return nil, false
|
||||
return false, nil
|
||||
}
|
||||
err := ns.getRemote(ns.cacheGetJSON, f, req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
if string(content) != string(c) {
|
||||
t.Fatalf("expected\n%q\ngot\n%q", content, c)
|
||||
t.Errorf("expected\n%q\ngot\n%q", content, c)
|
||||
}
|
||||
|
||||
time.Sleep(23 * time.Millisecond)
|
||||
|
Reference in New Issue
Block a user