This is a boilerplate for building RESTful APIs using Golang and the Fiber web framework. It includes a basic Todo application structure with database integration, JWT authentication, and Swagger documentation.
- Fiber web framework
- PostgreSQL database with GORM
- JWT authentication
- Swagger API documentation
- Docker support
- Air for live reloading during development
- Structured logging with zerolog
- Configuration management with Viper
- Error handling and custom middleware
- API versioning
- Go 1.23 or higher
- Docker and Docker Compose
- PostgreSQL
-
Clone the repository:
git clone https://github.com/yourusername/gofiber-boilerplate.git cd gofiber-boilerplate
-
Set up environment variables: Copy the
.env.example
file to.env
and update the values as needed. -
Run the application using Docker:
make docker-up
This will start the application and a PostgreSQL database in Docker containers.
-
Access the API at
http://localhost:8080/api/v1
-
View the Swagger documentation at
http://localhost:8080/swagger/
To run the application in development mode with live reloading:
make run
Run the tests with:
make test
To build the application:
make build
POST /api/v1/auth/register
: Register a new userPOST /api/v1/auth/login
: User loginPOST /api/v1/auth/logout
: User logoutPOST /api/v1/auth/refresh
: Refresh JWT token
POST /api/v1/todos
: Create a new todoGET /api/v1/todos
: List all todosGET /api/v1/todos/:id
: Get a specific todoPUT /api/v1/todos/:id
: Update a todoDELETE /api/v1/todos/:id
: Delete a todo
For detailed API documentation, refer to the Swagger UI.
cmd/
: Application entry pointconfig/
: Configuration managementinternal/
: Internal application codeapi/
: API-related codehandlers/
: HTTP request handlersmiddleware/
: Custom middlewareroutes/
: API route definitionsutils/
: API utility functions
db/
: Database connection and migrationsmodels/
: Data modelsrepositories/
: Data access layerservices/
: Business logic
docs/
: Swagger documentationmigrations/
: Database migration filesdocker/
: Docker-related files
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.