MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / LoadConfig

Function LoadConfig

conf/config.go:153–233  ·  view source on GitHub ↗

LoadConfig loads config from configPath.

(configPath string)

Source from the content-addressed store, hash-verified

151
152// LoadConfig loads config from configPath.
153func 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 {

Callers 15

setupFunction · 0.92
TestMetaStateFunction · 0.92
InitFunction · 0.92
initNodeFunction · 0.92
initFunction · 0.92
initNodeChainBusServiceFunction · 0.92
initNodeFunction · 0.92
TestCQLDFunction · 0.92
TestStartBP_CallRPCFunction · 0.92
mainFunction · 0.92
runConsoleFunction · 0.92

Calls 5

StringMethod · 0.95
WithErrorFunction · 0.92
PubKeyHashFunction · 0.92
ErrorMethod · 0.80
UnmarshalMethod · 0.80

Tested by 15

setupFunction · 0.74
TestMetaStateFunction · 0.74
initNodeFunction · 0.74
initNodeChainBusServiceFunction · 0.74
initNodeFunction · 0.74
TestCQLDFunction · 0.74
TestStartBP_CallRPCFunction · 0.74
TestIsPermittedFunction · 0.74
TestGenTestNetDomainFunction · 0.74
TestResolverFunction · 0.74
setupFunction · 0.74