naming.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package naming
  2. import (
  3. "context"
  4. )
  5. // metadata common key
  6. const (
  7. MetaColor = "color"
  8. MetaWeight = "weight"
  9. MetaCluster = "cluster"
  10. MetaZone = "zone"
  11. )
  12. // Instance represents a server the client connects to.
  13. type Instance struct {
  14. // Region bj/sh/gz
  15. Region string `json:"region"`
  16. // Zone is IDC.
  17. Zone string `json:"zone"`
  18. // Env prod/pre、uat/fat1
  19. Env string `json:"env"`
  20. // AppID is mapping servicetree appid.
  21. AppID string `json:"appid"`
  22. // Hostname is hostname from docker.
  23. Hostname string `json:"hostname"`
  24. // Addrs is the adress of app instance
  25. // format: scheme://host
  26. Addrs []string `json:"addrs"`
  27. // Version is publishing version.
  28. Version string `json:"version"`
  29. // LastTs is instance latest updated timestamp
  30. LastTs int64 `json:"latest_timestamp"`
  31. // Metadata is the information associated with Addr, which may be used
  32. // to make load balancing decision.
  33. Metadata map[string]string `json:"metadata"`
  34. Status int64
  35. }
  36. // Resolver resolve naming service
  37. type Resolver interface {
  38. Fetch(context.Context) (map[string][]*Instance, bool)
  39. //Unwatch(id string)
  40. Watch() <-chan struct{}
  41. Close() error
  42. }
  43. // Registry Register an instance and renew automatically
  44. type Registry interface {
  45. Register(context.Context, *Instance) (context.CancelFunc, error)
  46. Close() error
  47. }
  48. // Builder resolver builder.
  49. type Builder interface {
  50. Build(id string) Resolver
  51. Scheme() string
  52. }