17995: Merge branch 'main'
[arvados.git] / sdk / go / keepclient / root_sorter.go
index 7a73d957a0e9ed4bcaf1f37c7b7ec224f1ac6bfc..c46b7185e67958b6fc91bb6531364d11a9ff5238 100644 (file)
@@ -1,18 +1,20 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
 package keepclient
 
 import (
-       "crypto/md5"
-       "fmt"
        "sort"
 )
 
 type RootSorter struct {
-       root         []string
-       weight       []string
-       order        []int
+       root   []string
+       weight []string
+       order  []int
 }
 
-func NewRootSorter(serviceRoots map[string]string, hash string) (*RootSorter) {
+func NewRootSorter(serviceRoots map[string]string, hash string) *RootSorter {
        rs := new(RootSorter)
        rs.root = make([]string, len(serviceRoots))
        rs.weight = make([]string, len(serviceRoots))
@@ -28,18 +30,15 @@ func NewRootSorter(serviceRoots map[string]string, hash string) (*RootSorter) {
        return rs
 }
 
-func (rs RootSorter) getWeight(hash string, uuid string) (string) {
-       var service_key []byte
+func (rs RootSorter) getWeight(hash string, uuid string) string {
        if len(uuid) == 27 {
-               service_key = []byte(hash + uuid[12:])
-       } else {
-               // Only useful for testing, a set of one service root, etc.
-               service_key = []byte(hash + uuid)
+               return Md5String(hash + uuid[12:])
        }
-       return fmt.Sprintf("%x", md5.Sum(service_key))
+       // Only useful for testing, a set of one service root, etc.
+       return Md5String(hash + uuid)
 }
 
-func (rs RootSorter) GetSortedRoots() ([]string) {
+func (rs RootSorter) GetSortedRoots() []string {
        sorted := make([]string, len(rs.order))
        for i := range rs.order {
                sorted[i] = rs.root[rs.order[i]]