This is a created article in which the information may have evolved or changed.
Recent projects developed with Beego are frequently deployed to test environment for testing, and then deployed to the online release, because of the configuration files in the two environments different configuration parameters, each time the manual modification is cumbersome, so there is no way to load the environment according to the different deployment of the configuration variables.
Fortunately, colleagues told the two environments will inject env_cluster the system environment variables, and the variable value is different. So, in the main function Beego. Before run () execution, I created a pre-executed init file, where the code logic for loading the configuration file from the adaptive environment is placed.
The specific code is as follows:
env := os.Getenv("ENV_CLUSTER") if env == "online" { beego.AppConfigPath = "./conf/online.conf" } else if env == "beta" { beego.AppConfigPath = "./conf/beta.conf" } else { beego.AppConfigPath = "./conf/dev.conf" } beego.ParseConfig()