https://github.com/ahmadammarm/go-rest-api-template
Simple RESTful API template built using Go programming language and Fiber framework with many key features
https://github.com/ahmadammarm/go-rest-api-template
ci docker fiber go postgresql rest-api
Last synced: 2 months ago
JSON representation
Simple RESTful API template built using Go programming language and Fiber framework with many key features
- Host: GitHub
- URL: https://github.com/ahmadammarm/go-rest-api-template
- Owner: ahmadammarm
- Created: 2025-03-31T12:43:42.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-07-14T16:38:21.000Z (3 months ago)
- Last Synced: 2025-07-14T21:22:27.495Z (3 months ago)
- Topics: ci, docker, fiber, go, postgresql, rest-api
- Language: Go
- Homepage:
- Size: 79.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go REST API Template
A RESTful API template built with Go programming language.
    
## Prequisites
- Go 1.24 or later
- PostgreSQL 17 or later
- Docker (optional)## Features
- **Unit Testing**: Implement the unit testing in order to code maintenance.
- **Middleware**: Implement the JWT Auth for the middleware.
- **Service Layer**: Implement the service layer for separating business logic from application logic.
- **Repository Pattern**: Managing interactions with databases using the repository pattern.
- **CRUD Implementation**: Implement CRUD logic in the model entity.
- **Configuration**: Supports environment variables configuration via .env files.
- **CORS Support**: Supports Cross-Origin Resource Sharing (CORS) configuration.
- **Deployment**: Supports build and deploy using Docker.## REST API Design
The project provides a RESTful API for posts. The API follows standard REST conventions:
### Users API Routes
- `GET /api/v1/users` - Get all users.
- `GET /api/v1/user/:id` - Get an user by id.
- `POST /api/v1/user/register` - Register an user.
- `POST /api/v1/user/login` - Login for the registered user.### News API Routes
- `GET /api/v1/news` - Get all news.
- `GET /api/v1/news/:id` - Get a news by id.
- `POST /api/v1/news` - Create a news.
- `PUT /api/v1/news/:id` - Edit a news by id.
- `DELETE /api/v1/news/:id` - Delete a news by id.## Getting Started
1. Clone the repository:
```sh
git clone https://github.com/ahmadammarm/go-rest-api-template.git
```2. Navigate to the project directory:
```sh
cd go-rest-api-template
```3. Install the project dependencies:
```sh
go mod download
```4. Configure Environment Variable: Copy the file `.env.example` to `.env` and adjust it to your configuration:
```sh
cp .env.example .env
``````
POSTGRES_HOST=localhost
POSTGRES_PORT=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
JWT_SECRET_KEY=your-jwt-secret-key
CORS_ALLOW_ORIGINS=your-header-http-domain
```- POSTGRES: Configuration for PostgreSQL database connection.
- JWT_SECRET_KEY: The secret key used for JWT token signing and verification.
- CORS_ALLOW_ORIGINS: The allowed origins for Cross-Origin Resource Sharing (CORS). This is the domain that will be able to access resources from this API. For example, if you are running the frontend on http://localhost:5173, you should set this environment variable to http://localhost:5173.
5. Run the project:
```sh
go run cmd/main.go
```## Getting Started with Docker
1. Clone the repository:
```sh
git clone https://github.com/ahmadammarm/go-rest-api-template.git
```2. Navigate to the project directory:
```sh
cd go-rest-api-template
```3. Run the Docker Compose:
```sh
docker-compose up
```or run in detach mode:
```sh
docker-compose up -d
```4. To stop the Docker Compose:
```sh
docker-compose down
```The project will be available at:
`http://localhost:8080`
### This project also available for your contributions, thank you :)