Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

ItsCosmas/gofiber-boilerplate

Repository files navigation

MIT Licence Open Source Love

Go (Golang) and Fiber RESTful API Boilerplate

  • This can help you quickly start your new Go and Fiber web application.
  • Fiber and Go have been updated a lot since this was made.
  • There are some pretty gore patterns 😱 from my youth(excuse 😅) that should definitely not be used.
  • This repository still has useful configurations and code to get you started, but it's not a complete template that you can use without making changes.
  • For more up-to-date info please refer to Gofiber Recipes

Used libraries:


Features

  • Gofiber Docker Dev Setup with Hot Reload
  • User Auth functionality (Signup, Login, Forgot and Reset Password)
  • JWT Authentication
  • RESTful API
  • Swagger REST API documentation
  • Gorm (Golang SQL DB ORM) with Postgres implementation and auto migration
  • MongoDB using the official mongo driver
  • Configs via environmental variables
  • Improved Input Validations(could be better)
  • Custom Error messages
  • Email notification (Welcome email, Reset password email)
  • Redis
  • Casbin
  • WebSocket
  • gRPC
  • Improve MongoDB data integrity

Running and Developing locally

  1. Create .env , i.e.
cp .env.example .env
  1. Download and install Swag for generating docs
go install github.com/swaggo/swag/cmd/swag@latest
  1. Run
  • NOTE: You have to generate swagger docs before running the app.
# Terminal 1
swag init # Generates Swagger Docs

# Terminal 2
docker compose --env-file .env up        # docker compose up (Run App With AutoReload)
docker compose --env-file .env down      # docker compose down (Shutdown App)

Packaging For Production

  1. Create .env , i.e.
cp .env.example .env
  1. Update your .env variables for production
  • Point to your prod database
  • Update JWT issuer, secret key , blah blah
  • Basically just follow good production practice
  1. Download Swag for generating docs
  • Btw, you can use tags to exclude building swagger docs on prod
  • Currently, they're not served because of a check in routes, but are needed to be build
go install github.com/swaggo/swag/cmd/swag@latest
  • Generate Swagger Docs. You have to generate swagger docs before packaging the app.
swag init # Generates Swagger
  1. Build Your Image
  • Permission the build script to run.
chmod +x docker-build.sh
  • You could set the image port on Dockerfile.prod
  • Run the build script. You must provide a version tag as shown below.
./docker-build.sh -v gofiber:1.0.0

Todo

  • Data Migrations ?
  • Logger
  • Unit tests

maybe?

  • SMS notification (2FA ,Reset password code)
  • GraphQL
  • Deploy on Kubernetes
  • Write an article

Gotcha's

  • Building Swago from source code - go build -o swag.exe cmd/swag/main.go

Contribution

Open to Suggestions and Pull Requests

PRs Welcome

About

Go (Golang) and Fiber (Gofiber) RESTful API Boilerplate

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published