Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 23, 2020 12:20 am GMT

How to Deploy A Golang App to Heroku.

This is a step by step tutorial on how to deploy a Golang app on Heroku.

Requirements.

  1. Heroku Account
  2. Heroku CLI
  3. Golang v1.14 and above

Step 1.

Create a Heroku account using your email and password or log in if you already have an account.

Download the Heroku CLI by running the command below on Mac OS

$ brew tap heroku/brew && brew install heroku

Or go to https://devcenter.heroku.com/articles/heroku-cli#download-and-install to install on Windows.
Login to Heroku from your terminal using the command

$ heroku login

This will open your web browser to complete the login flow.

Step 2.

Create Procfile by running

$ touch Procfile

or just create it from the directory. Run echo "web: [directory]" > Procfile replace [directory] e.g

$ echo "web: currency" > Procfile

Step 3.

Generate a go.mod file using go mod init github.com/[user_name]/[project_name] e.g.

$ go mod init github.com/heavykenny/currency

Step 4.

Set variable names in.env file e.g. PORT=8080 using

$ heroku config:set PORT=8080

You can also set other variables using this command.

Step 5.

Commit your code using the following commands

$ git init$ git add . && git commit -m "Deploying to Heroku"

Step 6.

Create a Heroku application using heroku create [project_name] e.g.

$ heroku create go-currency$ git push heroku master

You can then proceed to test your app using https://[project_name].herokuapp.com i.e.
https://go-currency.herokuapp.com.

If you encounter any error during any of these processes, do not hesitate to comment or reach out. Thank you.


Original Link: https://dev.to/heavykenny/how-to-deploy-a-golang-app-to-heroku-5g1j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To