Fix more golint warnings.
authorWard Vandewege <ward@curii.com>
Thu, 26 Nov 2020 22:17:10 +0000 (17:17 -0500)
committerWard Vandewege <ward@curii.com>
Thu, 26 Nov 2020 22:17:10 +0000 (17:17 -0500)
No issue #

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

sdk/go/keepclient/hashcheck.go
sdk/go/keepclient/keepclient_test.go
sdk/go/keepclient/support.go

index 9295c14cc24a47cd38479e19a8aa57dc91c1c42a..0966e072eae6d354ad8664d935ce290fb35f7649 100644 (file)
@@ -29,36 +29,36 @@ type HashCheckingReader struct {
 // Reads from the underlying reader, update the hashing function, and
 // pass the results through. Returns BadChecksum (instead of EOF) on
 // the last read if the checksum doesn't match.
-func (this HashCheckingReader) Read(p []byte) (n int, err error) {
-       n, err = this.Reader.Read(p)
+func (hcr HashCheckingReader) Read(p []byte) (n int, err error) {
+       n, err = hcr.Reader.Read(p)
        if n > 0 {
-               this.Hash.Write(p[:n])
+               hcr.Hash.Write(p[:n])
        }
        if err == io.EOF {
-               sum := this.Hash.Sum(nil)
-               if fmt.Sprintf("%x", sum) != this.Check {
+               sum := hcr.Hash.Sum(nil)
+               if fmt.Sprintf("%x", sum) != hcr.Check {
                        err = BadChecksum
                }
        }
        return n, err
 }
 
-// WriteTo writes the entire contents of this.Reader to dest. Returns
+// WriteTo writes the entire contents of hcr.Reader to dest. Returns
 // BadChecksum if writing is successful but the checksum doesn't
 // match.
-func (this HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error) {
-       if writeto, ok := this.Reader.(io.WriterTo); ok {
-               written, err = writeto.WriteTo(io.MultiWriter(dest, this.Hash))
+func (hcr HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error) {
+       if writeto, ok := hcr.Reader.(io.WriterTo); ok {
+               written, err = writeto.WriteTo(io.MultiWriter(dest, hcr.Hash))
        } else {
-               written, err = io.Copy(io.MultiWriter(dest, this.Hash), this.Reader)
+               written, err = io.Copy(io.MultiWriter(dest, hcr.Hash), hcr.Reader)
        }
 
        if err != nil {
                return written, err
        }
 
-       sum := this.Hash.Sum(nil)
-       if fmt.Sprintf("%x", sum) != this.Check {
+       sum := hcr.Hash.Sum(nil)
+       if fmt.Sprintf("%x", sum) != hcr.Check {
                return written, BadChecksum
        }
 
@@ -68,10 +68,10 @@ func (this HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error
 // Close reads all remaining data from the underlying Reader and
 // returns BadChecksum if the checksum doesn't match. It also closes
 // the underlying Reader if it implements io.ReadCloser.
-func (this HashCheckingReader) Close() (err error) {
-       _, err = io.Copy(this.Hash, this.Reader)
+func (hcr HashCheckingReader) Close() (err error) {
+       _, err = io.Copy(hcr.Hash, hcr.Reader)
 
-       if closer, ok := this.Reader.(io.Closer); ok {
+       if closer, ok := hcr.Reader.(io.Closer); ok {
                closeErr := closer.Close()
                if err == nil {
                        err = closeErr
@@ -80,7 +80,7 @@ func (this HashCheckingReader) Close() (err error) {
        if err != nil {
                return err
        }
-       if fmt.Sprintf("%x", this.Hash.Sum(nil)) != this.Check {
+       if fmt.Sprintf("%x", hcr.Hash.Sum(nil)) != hcr.Check {
                return BadChecksum
        }
        return nil
index 59c4127240eee14a70680b96063d767ffe99ddce..57a89b50aa74362fcd4c5a229db2312b5870b249 100644 (file)
@@ -97,7 +97,7 @@ func (s *ServerRequiredSuite) TestDefaultReplications(c *C) {
 type StubPutHandler struct {
        c                  *C
        expectPath         string
-       expectApiToken     string
+       expectAPIToken     string
        expectBody         string
        expectStorageClass string
        handled            chan string
@@ -105,7 +105,7 @@ type StubPutHandler struct {
 
 func (sph StubPutHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
        sph.c.Check(req.URL.Path, Equals, "/"+sph.expectPath)
-       sph.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sph.expectApiToken))
+       sph.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sph.expectAPIToken))
        sph.c.Check(req.Header.Get("X-Keep-Storage-Classes"), Equals, sph.expectStorageClass)
        body, err := ioutil.ReadAll(req.Body)
        sph.c.Check(err, Equals, nil)
@@ -256,7 +256,7 @@ type KeepServer struct {
 func RunSomeFakeKeepServers(st http.Handler, n int) (ks []KeepServer) {
        ks = make([]KeepServer, n)
 
-       for i := 0; i < n; i += 1 {
+       for i := 0; i < n; i++ {
                ks[i] = RunFakeKeepServer(st)
        }
 
@@ -464,14 +464,14 @@ func (s *StandaloneSuite) TestPutWithTooManyFail(c *C) {
 type StubGetHandler struct {
        c              *C
        expectPath     string
-       expectApiToken string
+       expectAPIToken string
        httpStatus     int
        body           []byte
 }
 
 func (sgh StubGetHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
        sgh.c.Check(req.URL.Path, Equals, "/"+sgh.expectPath)
-       sgh.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sgh.expectApiToken))
+       sgh.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sgh.expectAPIToken))
        resp.WriteHeader(sgh.httpStatus)
        resp.Header().Set("Content-Length", fmt.Sprintf("%d", len(sgh.body)))
        resp.Write(sgh.body)
index 91117f2d3216ea317b05761b155a42e9e00f2da6..3b1afe1e288cdec5746cc69f167d10d89b57361b 100644 (file)
@@ -55,7 +55,7 @@ type uploadStatus struct {
        response       string
 }
 
-func (this *KeepClient) uploadToKeepServer(host string, hash string, body io.Reader,
+func (kc *KeepClient) uploadToKeepServer(host string, hash string, body io.Reader,
        uploadStatusChan chan<- uploadStatus, expectedLength int64, reqid string) {
 
        var req *http.Request
@@ -77,15 +77,15 @@ func (this *KeepClient) uploadToKeepServer(host string, hash string, body io.Rea
        }
 
        req.Header.Add("X-Request-Id", reqid)
-       req.Header.Add("Authorization", "OAuth2 "+this.Arvados.ApiToken)
+       req.Header.Add("Authorization", "OAuth2 "+kc.Arvados.ApiToken)
        req.Header.Add("Content-Type", "application/octet-stream")
-       req.Header.Add(XKeepDesiredReplicas, fmt.Sprint(this.Want_replicas))
-       if len(this.StorageClasses) > 0 {
-               req.Header.Add("X-Keep-Storage-Classes", strings.Join(this.StorageClasses, ", "))
+       req.Header.Add(XKeepDesiredReplicas, fmt.Sprint(kc.Want_replicas))
+       if len(kc.StorageClasses) > 0 {
+               req.Header.Add("X-Keep-Storage-Classes", strings.Join(kc.StorageClasses, ", "))
        }
 
        var resp *http.Response
-       if resp, err = this.httpClient().Do(req); err != nil {
+       if resp, err = kc.httpClient().Do(req); err != nil {
                DebugPrintf("DEBUG: [%s] Upload failed %v error: %v", reqid, url, err.Error())
                uploadStatusChan <- uploadStatus{err, url, 0, 0, err.Error()}
                return
@@ -116,15 +116,15 @@ func (this *KeepClient) uploadToKeepServer(host string, hash string, body io.Rea
        }
 }
 
-func (this *KeepClient) putReplicas(
+func (kc *KeepClient) putReplicas(
        hash string,
        getReader func() io.Reader,
        expectedLength int64) (locator string, replicas int, err error) {
 
-       reqid := this.getRequestID()
+       reqid := kc.getRequestID()
 
        // Calculate the ordering for uploading to servers
-       sv := NewRootSorter(this.WritableLocalRoots(), hash).GetSortedRoots()
+       sv := NewRootSorter(kc.WritableLocalRoots(), hash).GetSortedRoots()
 
        // The next server to try contacting
        nextServer := 0
@@ -147,15 +147,15 @@ func (this *KeepClient) putReplicas(
        }()
 
        replicasDone := 0
-       replicasTodo := this.Want_replicas
+       replicasTodo := kc.Want_replicas
 
-       replicasPerThread := this.replicasPerService
+       replicasPerThread := kc.replicasPerService
        if replicasPerThread < 1 {
                // unlimited or unknown
                replicasPerThread = replicasTodo
        }
 
-       retriesRemaining := 1 + this.Retries
+       retriesRemaining := 1 + kc.Retries
        var retryServers []string
 
        lastError := make(map[string]string)
@@ -169,7 +169,7 @@ func (this *KeepClient) putReplicas(
                                // Start some upload requests
                                if nextServer < len(sv) {
                                        DebugPrintf("DEBUG: [%s] Begin upload %s to %s", reqid, hash, sv[nextServer])
-                                       go this.uploadToKeepServer(sv[nextServer], hash, getReader(), uploadStatusChan, expectedLength, reqid)
+                                       go kc.uploadToKeepServer(sv[nextServer], hash, getReader(), uploadStatusChan, expectedLength, reqid)
                                        nextServer++
                                        active++
                                } else {