config.go 674 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package migrate
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "github.com/coreos/etcd/raft/raftpb"
  6. )
  7. type Config4 struct {
  8. CommitIndex uint64 `json:"commitIndex"`
  9. Peers []struct {
  10. Name string `json:"name"`
  11. ConnectionString string `json:"connectionString"`
  12. } `json:"peers"`
  13. }
  14. func (c *Config4) HardState2() raftpb.HardState {
  15. return raftpb.HardState{
  16. Commit: c.CommitIndex,
  17. Term: 0,
  18. Vote: 0,
  19. }
  20. }
  21. func DecodeConfig4FromFile(cfgPath string) (*Config4, error) {
  22. b, err := ioutil.ReadFile(cfgPath)
  23. if err != nil {
  24. return nil, err
  25. }
  26. conf := &Config4{}
  27. if err = json.Unmarshal(b, conf); err != nil {
  28. return nil, err
  29. }
  30. return conf, nil
  31. }