Skip to content

Commit e2d63de

Browse files
committed
some improvement
1 parent d4e51e2 commit e2d63de

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

modules/setting/setting.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,17 @@ func PrepareAppDataPath() error {
218218

219219
// LoadFromExisting initializes setting options from an existing config file (app.ini)
220220
func LoadFromExisting() {
221-
Cfg = loadFromConf(false, "")
221+
Cfg = loadFromConf(CustomConf, WritePIDFile, false, PIDFile, "")
222222
}
223223

224224
// LoadAllowEmpty initializes setting options, it's also fine that if the config file (app.ini) doesn't exist
225225
func LoadAllowEmpty() {
226-
Cfg = loadFromConf(true, "")
226+
Cfg = loadFromConf(CustomConf, WritePIDFile, true, PIDFile,"")
227227
}
228228

229229
// LoadForTest initializes setting options for tests
230230
func LoadForTest(extraConfigs ...string) {
231-
Cfg = loadFromConf(true, strings.Join(extraConfigs, "\n"))
231+
Cfg = loadFromConf(CustomConf, WritePIDFile, true, PIDFile,strings.Join(extraConfigs, "\n"))
232232
if err := PrepareAppDataPath(); err != nil {
233233
log.Fatal("Can not prepare APP_DATA_PATH: %v", err)
234234
}
@@ -249,20 +249,20 @@ func deprecatedSettingDB(rootCfg Config, oldSection, oldKey string) {
249249

250250
// loadFromConf initializes configuration context.
251251
// NOTE: do not print any log except error.
252-
func loadFromConf(allowEmpty bool, extraConfig string) *ini.File {
252+
func loadFromConf(customConf string, writePIDFile, allowEmpty bool, pidFile, extraConfig string) *ini.File {
253253
cfg := ini.Empty()
254254

255-
if WritePIDFile && len(PIDFile) > 0 {
256-
createPIDFile(PIDFile)
255+
if writePIDFile && len(pidFile) > 0 {
256+
createPIDFile(pidFile)
257257
}
258258

259-
isFile, err := util.IsFile(CustomConf)
259+
isFile, err := util.IsFile(customConf)
260260
if err != nil {
261-
log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
261+
log.Error("Unable to check if %s is a file. Error: %v", customConf, err)
262262
}
263263
if isFile {
264-
if err := cfg.Append(CustomConf); err != nil {
265-
log.Fatal("Failed to load custom conf '%s': %v", CustomConf, err)
264+
if err := cfg.Append(customConf); err != nil {
265+
log.Fatal("Failed to load custom conf '%s': %v", customConf, err)
266266
}
267267
} else if !allowEmpty {
268268
log.Fatal("Unable to find configuration file: %q.\nEnsure you are running in the correct environment or set the correct configuration file with -c.", CustomConf)

0 commit comments

Comments
 (0)