Heroku Deployment Example
This project demonstrates how to deploy a Go application using the Fiber framework on Heroku.
Prerequisites
Ensure you have the following installed:
- Golang
- Fiber package
- Heroku CLI
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/heroku -
Install dependencies:
go get
-
Log in to Heroku:
heroku login
-
Create a new Heroku application:
heroku create
-
Add a
Procfile
to the project directory with the following content:web: go run main.go
-
Deploy the application to Heroku:
git add .
git commit -m "Deploy to Heroku"
git push heroku master
Running the Application
- 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
}