Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 1.96 KB

README.md

File metadata and controls

97 lines (72 loc) · 1.96 KB
title keywords description
Heroku
heroku
deployment
Deploying to Heroku.

Heroku Deployment Example

Github StackBlitz

This project demonstrates how to deploy a Go application using the Fiber framework on Heroku.

Prerequisites

Ensure you have the following installed:

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/heroku
  2. Install dependencies:

    go get
  3. Log in to Heroku:

    heroku login
  4. Create a new Heroku application:

    heroku create
  5. Add a Procfile to the project directory with the following content:

    web: go run main.go
    
  6. Deploy the application to Heroku:

    git add .
    git commit -m "Deploy to Heroku"
    git push heroku master

Running the Application

  1. Open the application in your browser:
    heroku open

Example

Here is an example main.go file for the Fiber application:

package main

import (
    "log"
    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, Heroku!")
    })

    log.Fatal(app.Listen(":" + getPort()))
}

func getPort() string {
    port := os.Getenv("PORT")
    if port == "" {
        port = "3000"
    }
    return port
}

References