-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from valiner/env
use env replace flag
- Loading branch information
Showing
4 changed files
with
48 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* User: coder.sdp@gmail.com | ||
* Date: 2023/9/8 | ||
* Time: 14:18 | ||
*/ | ||
|
||
package zconf | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
// EnvConfigFilePathKey (Set configuration file path export ZINX_CONFIG_FILE_PATH = xxxxxxzinx.json) | ||
// (设置配置文件路径 export ZINX_CONFIG_FILE_PATH = xxx/xxx/zinx.json) | ||
EnvConfigFilePathKey = "ZINX_CONFIG_FILE_PATH" | ||
EnvDefaultConfigFilePath = "/conf/zinx.json" | ||
) | ||
|
||
var env = new(zEnv) | ||
|
||
type zEnv struct { | ||
configFilePath string | ||
} | ||
|
||
func init() { | ||
configFilePath := os.Getenv(EnvConfigFilePathKey) | ||
if configFilePath == "" { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
panic(err) | ||
} | ||
configFilePath = filepath.Join(pwd, EnvDefaultConfigFilePath) | ||
} | ||
var err error | ||
configFilePath, err = filepath.Abs(configFilePath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
env.configFilePath = configFilePath | ||
} | ||
|
||
func GetConfigFilePath() string { | ||
return env.configFilePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.