github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/test/e2e/app/config.go (about) 1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/BurntSushi/toml" 8 ) 9 10 // Config is the application configuration. 11 type Config struct { 12 ChainID string `toml:"chain_id"` 13 Listen string 14 Protocol string 15 Dir string 16 PersistInterval uint64 `toml:"persist_interval"` 17 SnapshotInterval uint64 `toml:"snapshot_interval"` 18 RetainBlocks uint64 `toml:"retain_blocks"` 19 ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"` 20 PrivValServer string `toml:"privval_server"` 21 PrivValKey string `toml:"privval_key"` 22 PrivValState string `toml:"privval_state"` 23 Misbehaviors map[string]string `toml:"misbehaviors"` 24 KeyType string `toml:"key_type"` 25 } 26 27 // LoadConfig loads the configuration from disk. 28 func LoadConfig(file string) (*Config, error) { 29 cfg := &Config{ 30 Listen: "unix:///var/run/app.sock", 31 Protocol: "builtin", 32 PersistInterval: 1, 33 } 34 _, err := toml.DecodeFile(file, &cfg) 35 if err != nil { 36 return nil, fmt.Errorf("failed to load config from %q: %w", file, err) 37 } 38 return cfg, cfg.Validate() 39 } 40 41 // Validate validates the configuration. We don't do exhaustive config 42 // validation here, instead relying on Testnet.Validate() to handle it. 43 func (cfg Config) Validate() error { 44 switch { 45 case cfg.ChainID == "": 46 return errors.New("chain_id parameter is required") 47 default: 48 return nil 49 } 50 }