initial import
This commit is contained in:
40
core/discov/clients.go
Normal file
40
core/discov/clients.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user