poolprovider-for-k8s/consistent-hash.go

22 строки
309 B
Go

package main
import (
"stathat.com/c/consistent"
)
func ComputeConsistentHash(nodes []string, key string) (string) {
c := consistent.New()
for _, items := range nodes {
s := items
if s != "" {
c.Add(s)
}
}
x, err := c.Get(key)
if err != nil {
return ""
}
return x
}