From 4b4cc5ebb9828bdd48c2300f1cb561becd8a074e Mon Sep 17 00:00:00 2001 From: jflyfox Date: Mon, 1 Mar 2021 17:02:07 +0800 Subject: [PATCH] improve package gcfg for main package path searching --- os/gcfg/gcfg.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/os/gcfg/gcfg.go b/os/gcfg/gcfg.go index 1256a6fa3..2c26abdf6 100644 --- a/os/gcfg/gcfg.go +++ b/os/gcfg/gcfg.go @@ -85,7 +85,16 @@ func New(file ...string) *Config { return c } +// getSearchPaths is used for checking and using `MainPkgPath` purpose. +// As the `MainPkgPath` is retrieved only by main goroutine, +// it should be checked multiple times when used in configuration file searching. +// It only makes sense in source development environment. func (c *Config) getSearchPaths() []string { + // Custom configuration directory path. + if !gcmd.GetOptWithEnv(fmt.Sprintf("%s.path", cmdEnvKey)).IsEmpty() { + return c.searchPaths.Slice() + } + var ( searchPaths = c.searchPaths.Slice() mainPkgPath = gfile.MainPkgPath()