+// 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))
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]]