How can I deploy beego app to Heroku

Recently I’ve searched go web app frameworks to create hobby project. I’ve been found this article Then I’ve looked all seven project github repos. I like project and start to develop app. I’ve been created API project and tried to deploy it to heroku. But there is no documention for it. So I’ve tried do that. This articles contains information about this process.

In order to deploy beego app to heroku you should use tools like

1. After install govendor try following steps in your project folder;

$ govendor init
This command will create ./vendor/vendor.json file in current directory.

  "comment": "",
  "heroku": {
    "install" : [ "./..." ],
    "goVersion": "go1.11"
  "ignore": "test",
  "package": [],
  "rootPath": "reporting-api"

Add heroku tag like above example. There is a information about this configuration on heroku docs in here

2. After this add beego package dependency with this command

$ govendor fetch It will download the beego packages to ./vendor directory

3. Lastly you should configure listen ports and beego runmode as prod for heroku in main.go file
To deploy your app without problem, default config must be runmode = prod in conf/app.conf. I tried to set it default as dev and change it from heroku config vars as below, but it compiles packages before the set runmode and gives exception with this message panic: you are running in dev mode.

func main() {
    log.Println("Env $PORT :", os.Getenv("PORT"))
    if os.Getenv("PORT") != "" {
        port, err := strconv.Atoi(os.Getenv("PORT"))
        if err != nil {
            log.Fatal("$PORT must be set")
        log.Println("port : ", port)
        beego.BConfig.Listen.HTTPPort = port
        beego.BConfig.Listen.HTTPSPort = port
    if os.Getenv("BEEGO_ENV") != "" {
        log.Println("Env $BEEGO_ENV :", os.Getenv("BEEGO_ENV"))
        beego.BConfig.RunMode = os.Getenv("BEEGO_ENV")

    beego.BConfig.WebConfig.DirectoryIndex = true
    beego.BConfig.WebConfig.StaticDir["/"] = "swagger"


You can use BEEGO_ENV=dev bee run to continue develop your app without change it again.

You can find example app in here

Please follow and like us:

Leave a Reply