config.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package migrate
  15. import (
  16. "encoding/json"
  17. "io/ioutil"
  18. "github.com/coreos/etcd/raft/raftpb"
  19. )
  20. type Config4 struct {
  21. CommitIndex uint64 `json:"commitIndex"`
  22. Peers []struct {
  23. Name string `json:"name"`
  24. ConnectionString string `json:"connectionString"`
  25. } `json:"peers"`
  26. }
  27. func (c *Config4) HardState2() raftpb.HardState {
  28. return raftpb.HardState{
  29. Commit: c.CommitIndex,
  30. Term: 0,
  31. Vote: 0,
  32. }
  33. }
  34. func DecodeConfig4FromFile(cfgPath string) (*Config4, error) {
  35. b, err := ioutil.ReadFile(cfgPath)
  36. if err != nil {
  37. return nil, err
  38. }
  39. conf := &Config4{}
  40. if err = json.Unmarshal(b, conf); err != nil {
  41. return nil, err
  42. }
  43. return conf, nil
  44. }