-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.go
53 lines (43 loc) · 1.1 KB
/
config.go
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 main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
const (
// dataDir defines the folder where to put the database files.
dataDir = "./data"
// defaultDebugLevel indicates the default debug level string.
defaultDebugLevel = "info"
// configFilename defines the configuration file name for the ELA node.
configFilename = "./config.json"
)
var (
// defaultConfig defines the default parameters to running a SPV client.
defaultConfig = configParams{
RPCPort: 20346,
DebugLevel: defaultDebugLevel,
}
cfg = loadConfig()
)
type configParams struct {
Network string
PermanentPeers []string
RPCPort uint16
DebugLevel string
}
func loadConfig() *configParams {
data, err := ioutil.ReadFile(configFilename)
if err != nil {
fmt.Printf("Read config file error %s", err)
os.Exit(-1)
}
// Remove the UTF-8 Byte Order Mark
data = bytes.TrimPrefix(data, []byte("\xef\xbb\xbf"))
// We have put the default configuration into config file, it's not mater
// whether unmarshall success or not.
json.Unmarshal(data, &defaultConfig)
return &defaultConfig
}