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.
41 lines
660 B
Go
41 lines
660 B
Go
package discov
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/tal-tech/go-zero/core/discov/internal"
|
|
)
|
|
|
|
const (
|
|
_ = 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)
|
|
}
|