This is an opinionated template for building a RESTful API via HTTP transport project using gofiber/fiber framework, with container support via Docker and CI/CD support via GitHub Actions.
- Dependency Injection via go.uber.org/fx
- Configuration via environment variable for easy container integration, utilizing
- kelseyhightower/envconfig for built-in common standard library value parsing support as well for custom value parsing support
- joho/godotenv for using
.env
files to ease local development
- Structured Logging via rs/zerolog for zero-allocation JSON/CBOR logging with support for log level, timestamp, and caller information, as well a human-readable render for local development
- Fastest Web Framework via gofiber/fiber with zero memory allocation and performance in mind
- Opinionated MVC Folder Structure following golang-standards/project-layout
- Database Integration via uptrace/bun
- Built-in Database Migration via uptrace/bun/migrate
- Easily write complex queries, at the same time still have ready to use struct-based CRUD operations
- CI/CD via GitHub Actions
.github/workflows/build-check.yml
for continuously checking the build status of the project by building the docker image of the project but not pushing it to the registry.github/workflows/build-release.yml
for releasing a version, in which GitHub Actions:- Builds container image with automatically generated OCI Image Format Specification labels via docker/metadata-action
- Pushes the image to GitHub Container Registry
- Creates a GitHub Release with automatically generated GitHub Release Notes via marvinpinto/action-automatic-releases
This repository is meant to be used as a template for your own project. You can use the Use this template
button on the top right corner of this page to create your own repository from this template.
If you want to clone this repository, you can do so by running the following command:
git clone [email protected]:GalvinGao/gofiber-template.git
DATABASE_URL=postgres://USERNAME:PASSWORD@localhost:5432/DATABASE_NAME?sslmode=disable
More information about database URL can be found in bun's documentation
go run main.go db init
go run main.go db migrate
gow stands for Go Watch. It is a tool that watches your Go source code and automatically recompiles and restarts your program when necessary. This allows you to see changes in real time which makes development much easier and faster.
go install github.com/mitranim/gow@latest
After you install gow
simply replace go
with gow
and start the server using:
gow run main.go start
Use the following .vscode/launch.json
to launch the application with debugger attached:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"args": ["start"]
}
]
}
Issues and pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.