Skip to content

ItsCosmas/gofiber-boilerplate

Repository files navigation

MIT Licence Open Source Love

Go (Golang) and Fiber RESTful API Boilerplate

🚧 WORK IN PROGRESS

  • Could be used to provide quick bootstrap functionality for your next go and gofiber app.
  • I will update(try) this regularly to add functionality and new features.
  • Well this is just one way of doing it, not the official or the best 😅.

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 at src, i.e.
cp src/.env.example src/.env
  1. Download Swag for generating docs
go get -u github.com/swaggo/swag/cmd/swag
  1. Run
  • NOTE: You have to generate swagger docs before running the app.
# Terminal 1
swag init -g src/api/app.go --output ./src/api/docs # Generates Swagger

# Terminal 2
docker-compose --env-file ./src/.env up        # docker-compose up (Run App With AutoReload)
docker-compose --env-file ./src/.env down      # docker-compose down (Shutdown App)
  • API http://localhost:8000/api/v1
  • Swagger Doc http://localhost:8000/api/v1/docs

Packaging For Production

  1. Create .env at src, i.e.
cp src/.env.example src/.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
go get -u github.com/swaggo/swag/cmd/swag
  • Generate Swagger Docs. You have to generate swagger docs before packaging the app.
swag init -g src/api/app.go --output ./src/api/docs # 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

Releases

No releases published

Packages

No packages published