-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
61 lines (47 loc) · 1.36 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
54
55
56
57
58
59
60
61
package main
import (
"path/filepath"
"github.com/sedracoin/sedrad/infrastructure/config"
"github.com/sedracoin/sedrad/infrastructure/logger"
"github.com/sedracoin/sedrad/stability-tests/common"
"github.com/sedracoin/sedrad/stability-tests/common/rpc"
"github.com/jessevdk/go-flags"
)
const (
defaultLogFilename = "json_stability.log"
defaultErrLogFilename = "json_stability_err.log"
)
var (
// Default configuration options
defaultLogFile = filepath.Join(common.DefaultAppDir, defaultLogFilename)
defaultErrLogFile = filepath.Join(common.DefaultAppDir, defaultErrLogFilename)
)
type configFlags struct {
rpc.Config
config.NetworkFlags
CommandsFilePath string `long:"commands" short:"p" description:"Path to commands file"`
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
}
var cfg *configFlags
func activeConfig() *configFlags {
return cfg
}
func parseConfig() error {
cfg = &configFlags{}
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
_, err := parser.Parse()
if err != nil {
return err
}
err = cfg.ResolveNetwork(parser)
if err != nil {
return err
}
err = rpc.ValidateRPCConfig(&cfg.Config)
if err != nil {
return err
}
log.SetLevel(logger.LevelInfo)
common.InitBackend(backendLog, defaultLogFile, defaultErrLogFile)
return nil
}