viper β
Priority Description β
The path variable parameter is to leave an opening for unit testing, convenient to use relative path or absolute path to specify the location of the config file
Use
./server -c xxx/config.yamlto pass values through command line and assign to config variableConfigEnv is a constant defined in server/core/internal/constant.go, you can modify it to your desired environment variable
Finally, it will match the definition in
server/core/internal/constant.gofile according to theGIN_MODEenvironment variable that comes with the Gin framework.Note
GIN_MODE can only have three values: debug, release, test, other values will panic
GIN_MODE Usage Scenario Description β
- There are three branches: development branch develop, test branch test, production branch release
- But the databases and OSS connected by the three branches are different, so there will be three configuration files, which cannot be saved in documents
- So generally use git's .gitattributes file, each branch has its own branch's configuration file and Dockerfile
- In the Dockerfile file, specify any of the following lines of code to control the configuration file corresponding to each environment
ENV GIN_MODE=debug
ENV GIN_MODE=release
ENV GIN_MODE=test

