config.go 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package etcdserver
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/coreos/etcd/pkg/types"
  6. )
  7. // ServerConfig holds the configuration of etcd as taken from the command line or discovery.
  8. type ServerConfig struct {
  9. Name string
  10. DiscoveryURL string
  11. ClientURLs types.URLs
  12. DataDir string
  13. SnapCount uint64
  14. Cluster *Cluster
  15. ClusterState ClusterState
  16. Transport *http.Transport
  17. }
  18. // Verify sanity-checks the config struct and returns an error for things that
  19. // should never happen.
  20. func (c *ServerConfig) Verify() error {
  21. // Make sure the cluster at least contains the local server.
  22. m := c.Cluster.FindName(c.Name)
  23. if m == nil {
  24. return fmt.Errorf("could not find name %v in cluster", c.Name)
  25. }
  26. // No identical IPs in the cluster peer list
  27. urlMap := make(map[string]bool)
  28. for _, m := range *c.Cluster {
  29. for _, url := range m.PeerURLs {
  30. if urlMap[url] {
  31. return fmt.Errorf("duplicate url %v in server config", url)
  32. }
  33. urlMap[url] = true
  34. }
  35. }
  36. return nil
  37. }