X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e158f485053be1e840073b321033d60d686a55a8..de6d121eac429a1dc65e3c3e646f45d54bcfcbf3:/sdk/go/keepclient/root_sorter.go diff --git a/sdk/go/keepclient/root_sorter.go b/sdk/go/keepclient/root_sorter.go index 7a73d957a0..afeb802849 100644 --- a/sdk/go/keepclient/root_sorter.go +++ b/sdk/go/keepclient/root_sorter.go @@ -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,16 @@ 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:]) + return Md5String(hash + uuid[12:]) } else { // Only useful for testing, a set of one service root, etc. - service_key = []byte(hash + uuid) + return Md5String(hash + uuid) } - return fmt.Sprintf("%x", md5.Sum(service_key)) } -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]]