-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
53 lines (47 loc) · 1.13 KB
/
config.go
File metadata and controls
53 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package kvraft
import (
"encoding/json"
"fmt"
"os"
)
type KVRaftConfig struct {
RaftAddr string
RaftPort string
RpcAddr string
RpcPort string
LeaderRpcAddr string
LeaderRpcPort string
MemberName string // {ip}:{port}
MemberAddr string
MemberPort int
PeerStorage string
Peers []string
SnapshotStorage string
DbDir string
EnableSingleNode bool
RaftLogDir string
BucketName string
Durable bool
}
func (rc *KVRaftConfig) RaftAddrString() string {
return fmt.Sprintf("%s:%s", rc.RaftAddr, rc.RaftPort)
}
func (rc *KVRaftConfig) RpcAddrString() string {
return fmt.Sprintf("%s:%s", rc.RpcAddr, rc.RpcPort)
}
func (rc *KVRaftConfig) MemberAddrString() string {
return fmt.Sprintf("%s:%s", rc.MemberAddr, rc.MemberPort)
}
func NewKVRaftConfig(confPath string) (*KVRaftConfig, error) {
kvraftConfig := &KVRaftConfig{}
cFile, err := os.Open(confPath)
if err != nil {
return nil, err
}
defer cFile.Close()
err = json.NewDecoder(cFile).Decode(kvraftConfig)
if err != nil {
return nil, err
}
return kvraftConfig, nil
}