-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (44 loc) · 1.03 KB
/
config.go
File metadata and controls
51 lines (44 loc) · 1.03 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
package main
import (
"encoding/json"
"fmt"
"os"
)
type ServerConfig struct {
ServerAddr string
ServerPort string
RaftAddr string
RaftPort string
RpcAddr string
RpcPort string
LeaderAddr string
LeaderPort string
PeerStorage string
Peers []string
SnapshotStorage string
DbPath string
LogDir string
EnableSingleNode bool
BucketName string
}
func (sc *ServerConfig) RaftAddrString() string {
return fmt.Sprintf("%s:%s", sc.RaftAddr, sc.RaftPort)
}
func (sc *ServerConfig) RpcAddrString() string {
return fmt.Sprintf("%s:%s", sc.RpcAddr, sc.RpcPort)
}
//Conf content must be formatted by json
var serverConfig *ServerConfig
func NewServerConfig(confPath string) (*ServerConfig, error) {
serverConfig = &ServerConfig{}
cFile, err := os.Open(confPath)
if err != nil {
return nil, err
}
defer cFile.Close()
err = json.NewDecoder(cFile).Decode(serverConfig)
if err != nil {
return nil, err
}
return serverConfig, nil
}