LoadConfig load the common covenantsql client config again for extra faucet config.
(listenAddr string, configPath string)
| 149 | |
| 150 | // LoadConfig load the common covenantsql client config again for extra faucet config. |
| 151 | func LoadConfig(listenAddr string, configPath string) (config *Config, err error) { |
| 152 | var configBytes []byte |
| 153 | if configBytes, err = ioutil.ReadFile(configPath); err != nil { |
| 154 | log.WithError(err).Error("read config file failed") |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | configWrapper := &confWrapper{} |
| 159 | if err = yaml.Unmarshal(configBytes, configWrapper); err != nil { |
| 160 | log.WithError(err).Error("unmarshal config file failed") |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | if configWrapper.Proxy == nil { |
| 165 | err = ErrInvalidProxyConfig |
| 166 | log.WithError(err).Error("could not read proxy config") |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | config = configWrapper.Proxy |
| 171 | |
| 172 | // override config |
| 173 | if listenAddr != "" { |
| 174 | config.ListenAddr = listenAddr |
| 175 | } |
| 176 | |
| 177 | err = config.Validate() |
| 178 | |
| 179 | return |
| 180 | } |