Fix some golint warnings.
authorWard Vandewege <ward@curii.com>
Sat, 29 Aug 2020 11:20:19 +0000 (07:20 -0400)
committerWard Vandewege <ward@curii.com>
Sat, 29 Aug 2020 11:20:19 +0000 (07:20 -0400)
No issue #

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

lib/controller/rpc/conn.go
lib/crunchrun/crunchrun.go
lib/dispatchcloud/driver.go
lib/dispatchcloud/test/stub_driver.go
sdk/go/arvados/blob_signature.go
sdk/go/arvados/config.go
sdk/go/arvados/keep_service.go
sdk/go/arvadosclient/arvadosclient.go
sdk/go/keepclient/root_sorter.go
sdk/go/keepclient/support.go

index 729d8bdde09e7ee05d2766ef0a4d1ee72f01a8d1..6c332db077434e90b9165d403f6eeb20ae2562c1 100644 (file)
@@ -28,9 +28,8 @@ type TokenProvider func(context.Context) ([]string, error)
 func PassthroughTokenProvider(ctx context.Context) ([]string, error) {
        if incoming, ok := auth.FromContext(ctx); !ok {
                return nil, errors.New("no token provided")
-       } else {
-               return incoming.Tokens, nil
        }
+       return incoming.Tokens, nil
 }
 
 type Conn struct {
@@ -170,9 +169,8 @@ func (conn *Conn) relativeToBaseURL(location string) string {
                u.User = nil
                u.Host = ""
                return u.String()
-       } else {
-               return location
        }
+       return location
 }
 
 func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
index c8f171ca9b83f38d1e2870af16913a4175db6490..c125b27a5f0783fe757bcf29ac0b62674b68df95 100644 (file)
@@ -870,25 +870,24 @@ func (runner *ContainerRunner) LogNodeRecord() error {
                        return err
                }
                return w.Close()
-       } else {
-               // Dispatched via crunch-dispatch-slurm. Look up
-               // apiserver's node record corresponding to
-               // $SLURMD_NODENAME.
-               hostname := os.Getenv("SLURMD_NODENAME")
-               if hostname == "" {
-                       hostname, _ = os.Hostname()
-               }
-               _, err := runner.logAPIResponse("node", "nodes", map[string]interface{}{"filters": [][]string{{"hostname", "=", hostname}}}, func(resp interface{}) {
-                       // The "info" field has admin-only info when
-                       // obtained with a privileged token, and
-                       // should not be logged.
-                       node, ok := resp.(map[string]interface{})
-                       if ok {
-                               delete(node, "info")
-                       }
-               })
-               return err
        }
+       // Dispatched via crunch-dispatch-slurm. Look up
+       // apiserver's node record corresponding to
+       // $SLURMD_NODENAME.
+       hostname := os.Getenv("SLURMD_NODENAME")
+       if hostname == "" {
+               hostname, _ = os.Hostname()
+       }
+       _, err := runner.logAPIResponse("node", "nodes", map[string]interface{}{"filters": [][]string{{"hostname", "=", hostname}}}, func(resp interface{}) {
+               // The "info" field has admin-only info when
+               // obtained with a privileged token, and
+               // should not be logged.
+               node, ok := resp.(map[string]interface{})
+               if ok {
+                       delete(node, "info")
+               }
+       })
+       return err
 }
 
 func (runner *ContainerRunner) logAPIResponse(label, path string, params map[string]interface{}, munge func(interface{})) (logged bool, err error) {
@@ -1489,7 +1488,7 @@ func (runner *ContainerRunner) ContainerToken() (string, error) {
        return runner.token, nil
 }
 
-// UpdateContainerComplete updates the container record state on API
+// UpdateContainerFinal updates the container record state on API
 // server to "Complete" or "Cancelled"
 func (runner *ContainerRunner) UpdateContainerFinal() error {
        update := arvadosclient.Dict{}
index f2a6c9263027dc2d765fc79720ec8bfeae2606e6..fe498d0484b0d41a0ceb0428aafc68a879033cc6 100644 (file)
@@ -17,7 +17,7 @@ import (
        "golang.org/x/crypto/ssh"
 )
 
-// Map of available cloud drivers.
+// Drivers is a map of available cloud drivers.
 // Clusters.*.Containers.CloudVMs.Driver configuration values
 // correspond to keys in this map.
 var Drivers = map[string]cloud.Driver{
@@ -180,7 +180,6 @@ func (inst instrumentedInstance) SetTags(tags cloud.InstanceTags) error {
 func boolLabelValue(v bool) string {
        if v {
                return "1"
-       } else {
-               return "0"
        }
+       return "0"
 }
index f6e06d3f7cebd05a97c8851f65d8d79812d18297..41eb20763c75248c6cea81a2e9854ad2dfde42a8 100644 (file)
@@ -118,10 +118,8 @@ func (sis *StubInstanceSet) Create(it arvados.InstanceType, image cloud.ImageID,
        }
        if sis.allowCreateCall.After(time.Now()) {
                return nil, RateLimitError{sis.allowCreateCall}
-       } else {
-               sis.allowCreateCall = time.Now().Add(sis.driver.MinTimeBetweenCreateCalls)
        }
-
+       sis.allowCreateCall = time.Now().Add(sis.driver.MinTimeBetweenCreateCalls)
        ak := sis.driver.AuthorizedKeys
        if authKey != nil {
                ak = append([]ssh.PublicKey{authKey}, ak...)
@@ -154,9 +152,8 @@ func (sis *StubInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, err
        defer sis.mtx.RUnlock()
        if sis.allowInstancesCall.After(time.Now()) {
                return nil, RateLimitError{sis.allowInstancesCall}
-       } else {
-               sis.allowInstancesCall = time.Now().Add(sis.driver.MinTimeBetweenInstancesCalls)
        }
+       sis.allowInstancesCall = time.Now().Add(sis.driver.MinTimeBetweenInstancesCalls)
        var r []cloud.Instance
        for _, ss := range sis.servers {
                r = append(r, ss.Instance())
@@ -372,10 +369,9 @@ func (svm *StubVM) Exec(env map[string]string, command string, stdin io.Reader,
                if running {
                        fmt.Fprintf(stderr, "%s: container is running\n", uuid)
                        return 1
-               } else {
-                       fmt.Fprintf(stderr, "%s: container is not running\n", uuid)
-                       return 0
                }
+               fmt.Fprintf(stderr, "%s: container is not running\n", uuid)
+               return 0
        }
        if command == "true" {
                return 0
index 132939547a6180b71266d102f52915e36988eb38..2202016bcc6b8a607c7f7d8241c80166247b87b4 100644 (file)
@@ -57,9 +57,8 @@ func SignManifest(manifest string, apiToken string, expiry time.Time, ttl time.D
        return regexp.MustCompile(`\S+`).ReplaceAllStringFunc(manifest, func(tok string) string {
                if mBlkRe.MatchString(tok) {
                        return SignLocator(mPermHintRe.ReplaceAllString(tok, ""), apiToken, expiry, ttl, permissionSecret)
-               } else {
-                       return tok
                }
+               return tok
        })
 }
 
index d98ffd18ed154c6882eb64c16f3af47bbc8c4b94..6e1549224b79c15e3674b76091c06a229589f16d 100644 (file)
@@ -17,9 +17,8 @@ import (
 var DefaultConfigFile = func() string {
        if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
                return path
-       } else {
-               return "/etc/arvados/config.yml"
        }
+       return "/etc/arvados/config.yml"
 }()
 
 type Config struct {
index da1710374e1e69ca4bfe6c2f77c8b990a1f7dc4e..eb7988422d80bc1f3d314ce36427c39788835c25 100644 (file)
@@ -140,7 +140,7 @@ func (s *KeepService) Untrash(ctx context.Context, c *Client, blk string) error
        return nil
 }
 
-// Index returns an unsorted list of blocks at the given mount point.
+// IndexMount returns an unsorted list of blocks at the given mount point.
 func (s *KeepService) IndexMount(ctx context.Context, c *Client, mountUUID string, prefix string) ([]KeepServiceIndexEntry, error) {
        return s.index(ctx, c, s.url("mounts/"+mountUUID+"/blocks?prefix="+prefix))
 }
index e2c046662769f4ebd3956394375ab59cde7ebe51..bfcbde2a70632a170734e2664683223f4740d695 100644 (file)
@@ -70,12 +70,11 @@ func (e APIServerError) Error() string {
                        e.HttpStatusCode,
                        e.HttpStatusMessage,
                        e.ServerAddress)
-       } else {
-               return fmt.Sprintf("arvados API server error: %d: %s returned by %s",
-                       e.HttpStatusCode,
-                       e.HttpStatusMessage,
-                       e.ServerAddress)
        }
+       return fmt.Sprintf("arvados API server error: %d: %s returned by %s",
+               e.HttpStatusCode,
+               e.HttpStatusMessage,
+               e.ServerAddress)
 }
 
 // StringBool tests whether s is suggestive of true. It returns true
@@ -420,9 +419,8 @@ func (c *ArvadosClient) Discovery(parameter string) (value interface{}, err erro
        value, found = c.DiscoveryDoc[parameter]
        if found {
                return value, nil
-       } else {
-               return value, ErrInvalidArgument
        }
+       return value, ErrInvalidArgument
 }
 
 func (ac *ArvadosClient) httpClient() *http.Client {
index afeb8028496532dc66550ddddf4bd15b285bc7e9..c46b7185e67958b6fc91bb6531364d11a9ff5238 100644 (file)
@@ -33,10 +33,9 @@ func NewRootSorter(serviceRoots map[string]string, hash string) *RootSorter {
 func (rs RootSorter) getWeight(hash string, uuid string) string {
        if len(uuid) == 27 {
                return Md5String(hash + uuid[12:])
-       } else {
-               // Only useful for testing, a set of one service root, etc.
-               return Md5String(hash + uuid)
        }
+       // Only useful for testing, a set of one service root, etc.
+       return Md5String(hash + uuid)
 }
 
 func (rs RootSorter) GetSortedRoots() []string {
index 71b4b5ed2608729a05111dc7ab327886f5332b47..7989e66c03728fbf383946c4fb7a21ed03199ac3 100644 (file)
@@ -127,7 +127,7 @@ func (this *KeepClient) putReplicas(
        sv := NewRootSorter(this.WritableLocalRoots(), hash).GetSortedRoots()
 
        // The next server to try contacting
-       next_server := 0
+       nextServer := 0
 
        // The number of active writers
        active := 0
@@ -162,15 +162,15 @@ func (this *KeepClient) putReplicas(
 
        for retriesRemaining > 0 {
                retriesRemaining -= 1
-               next_server = 0
+               nextServer = 0
                retryServers = []string{}
                for replicasTodo > 0 {
                        for active*replicasPerThread < replicasTodo {
                                // Start some upload requests
-                               if next_server < len(sv) {
-                                       DebugPrintf("DEBUG: [%s] Begin upload %s to %s", reqid, hash, sv[next_server])
-                                       go this.uploadToKeepServer(sv[next_server], hash, getReader(), upload_status, expectedLength, reqid)
-                                       next_server += 1
+                               if nextServer < len(sv) {
+                                       DebugPrintf("DEBUG: [%s] Begin upload %s to %s", reqid, hash, sv[nextServer])
+                                       go this.uploadToKeepServer(sv[nextServer], hash, getReader(), upload_status, expectedLength, reqid)
+                                       nextServer += 1
                                        active += 1
                                } else {
                                        if active == 0 && retriesRemaining == 0 {
@@ -180,9 +180,8 @@ func (this *KeepClient) putReplicas(
                                                }
                                                msg = msg[:len(msg)-2]
                                                return locator, replicasDone, InsufficientReplicasError(errors.New(msg))
-                                       } else {
-                                               break
                                        }
+                                       break
                                }
                        }
                        DebugPrintf("DEBUG: [%s] Replicas remaining to write: %v active uploads: %v",