clients.go 699 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package discov
  2. import (
  3. "fmt"
  4. "strings"
  5. "git.i2edu.net/i2/go-zero/core/discov/internal"
  6. )
  7. const (
  8. _ = iota
  9. indexOfId
  10. )
  11. const timeToLive int64 = 10
  12. // TimeToLive is seconds to live in etcd.
  13. var TimeToLive = timeToLive
  14. func extract(etcdKey string, index int) (string, bool) {
  15. if index < 0 {
  16. return "", false
  17. }
  18. fields := strings.FieldsFunc(etcdKey, func(ch rune) bool {
  19. return ch == internal.Delimiter
  20. })
  21. if index >= len(fields) {
  22. return "", false
  23. }
  24. return fields[index], true
  25. }
  26. func extractId(etcdKey string) (string, bool) {
  27. return extract(etcdKey, indexOfId)
  28. }
  29. func makeEtcdKey(key string, id int64) string {
  30. return fmt.Sprintf("%s%c%d", key, internal.Delimiter, id)
  31. }