LoadConfig loads config from configPath.
(configPath string)
| 151 | |
| 152 | // LoadConfig loads config from configPath. |
| 153 | func LoadConfig(configPath string) (config *Config, err error) { |
| 154 | configBytes, err := ioutil.ReadFile(configPath) |
| 155 | if err != nil { |
| 156 | log.WithError(err).Error("read config file failed") |
| 157 | return |
| 158 | } |
| 159 | config = &Config{} |
| 160 | err = yaml.Unmarshal(configBytes, config) |
| 161 | if err != nil { |
| 162 | log.WithError(err).Error("unmarshal config file failed") |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | if config.BPPeriod == time.Duration(0) { |
| 167 | config.BPPeriod = 10 * time.Second |
| 168 | } |
| 169 | |
| 170 | if config.WorkingRoot == "" { |
| 171 | config.WorkingRoot = "./" |
| 172 | } |
| 173 | |
| 174 | if config.PrivateKeyFile == "" { |
| 175 | config.PrivateKeyFile = "private.key" |
| 176 | } |
| 177 | |
| 178 | if config.PubKeyStoreFile == "" { |
| 179 | config.PubKeyStoreFile = "public.keystore" |
| 180 | } |
| 181 | if config.DHTFileName == "" { |
| 182 | config.DHTFileName = "dht.db" |
| 183 | } |
| 184 | |
| 185 | configDir := path.Dir(configPath) |
| 186 | if !path.IsAbs(config.PubKeyStoreFile) { |
| 187 | config.PubKeyStoreFile = path.Join(configDir, config.PubKeyStoreFile) |
| 188 | } |
| 189 | |
| 190 | if !path.IsAbs(config.PrivateKeyFile) { |
| 191 | config.PrivateKeyFile = path.Join(configDir, config.PrivateKeyFile) |
| 192 | } |
| 193 | |
| 194 | if !path.IsAbs(config.DHTFileName) { |
| 195 | config.DHTFileName = path.Join(configDir, config.DHTFileName) |
| 196 | } |
| 197 | |
| 198 | if !path.IsAbs(config.WorkingRoot) { |
| 199 | config.WorkingRoot = path.Join(configDir, config.WorkingRoot) |
| 200 | } |
| 201 | |
| 202 | if config.BP != nil && !path.IsAbs(config.BP.ChainFileName) { |
| 203 | config.BP.ChainFileName = path.Join(configDir, config.BP.ChainFileName) |
| 204 | } |
| 205 | |
| 206 | if config.Miner != nil && !path.IsAbs(config.Miner.RootDir) { |
| 207 | config.Miner.RootDir = path.Join(configDir, config.Miner.RootDir) |
| 208 | } |
| 209 | |
| 210 | if len(config.KnownNodes) > 0 { |