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