Beego load the appropriate configuration file under the deployment environment

Source: Internet
Author: User
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()
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.