You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/discov/clients.go

41 lines
646 B
Go

4 years ago
package discov
import (
"fmt"
"strings"
"zero/core/discov/internal"
)
const (
indexOfKey = iota
indexOfId
)
const timeToLive int64 = 10
var TimeToLive = timeToLive
func extract(etcdKey string, index int) (string, bool) {
if index < 0 {
return "", false
}
fields := strings.FieldsFunc(etcdKey, func(ch rune) bool {
return ch == internal.Delimiter
})
if index >= len(fields) {
return "", false
}
return fields[index], true
}
func extractId(etcdKey string) (string, bool) {
return extract(etcdKey, indexOfId)
}
func makeEtcdKey(key string, id int64) string {
return fmt.Sprintf("%s%c%d", key, internal.Delimiter, id)
}