{"id":23971333,"url":"https://github.com/laa-software-engineering/golang-rest-api-template","last_synced_at":"2025-10-24T13:53:08.353Z","repository":{"id":125834250,"uuid":"549246113","full_name":"LAA-Software-Engineering/golang-rest-api-template","owner":"LAA-Software-Engineering","description":"Template for REST API made with Golang using Gin framework, PostgreSQL database, JWT authentication, Redis cache and MongoDB for logging","archived":false,"fork":false,"pushed_at":"2025-03-17T21:17:50.000Z","size":54836,"stargazers_count":176,"open_issues_count":9,"forks_count":38,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-04T13:13:20.881Z","etag":null,"topics":["gin-framework","gin-gonic","go-example","go-rest-api","go-rest-api-docker","go-restful","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LAA-Software-Engineering.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-10T22:44:48.000Z","updated_at":"2025-03-28T00:15:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"37953a0a-34e5-4193-9d41-802e0a291ada","html_url":"https://github.com/LAA-Software-Engineering/golang-rest-api-template","commit_stats":{"total_commits":63,"total_committers":3,"mean_commits":21.0,"dds":0.2857142857142857,"last_synced_commit":"dbe3d6339fa7c97248978d4d36a7b215e45a7d3a"},"previous_names":["laa-software-engineering/golang-rest-api-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LAA-Software-Engineering%2Fgolang-rest-api-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LAA-Software-Engineering%2Fgolang-rest-api-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LAA-Software-Engineering%2Fgolang-rest-api-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LAA-Software-Engineering%2Fgolang-rest-api-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LAA-Software-Engineering","download_url":"https://codeload.github.com/LAA-Software-Engineering/golang-rest-api-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190236,"owners_count":20898700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gin-framework","gin-gonic","go-example","go-rest-api","go-rest-api-docker","go-restful","golang"],"created_at":"2025-01-07T03:00:47.468Z","updated_at":"2025-10-24T13:53:03.323Z","avatar_url":"https://github.com/LAA-Software-Engineering.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golang-rest-api-template\n\n[![license](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/araujo88/golang-rest-api-template/main/LICENSE)\n[![build](https://github.com/araujo88/golang-rest-api-template//actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/araujo88/golang-rest-api-template/actions/workflows/go.yml)\n\n## Overview\n\nThis repository provides a template for building a RESTful API using Go with features like JWT Authentication, rate limiting, Swagger documentation, and database operations using GORM. The application uses the Gin Gonic web framework and is containerized using Docker.\n\n## Features\n\n- RESTful API endpoints for CRUD operations.\n- JWT Authentication.\n- Rate Limiting.\n- Swagger Documentation.\n- PostgreSQL database integration using GORM.\n- Redis cache.\n- MongoDB for logging storage.\n- Dockerized application for easy setup and deployment.\n\n## Folder structure\n\n```\ngolang-rest-api-template/\n├── bin\n│  └── server\n├── cmd\n│  └── server\n│     └── main.go\n├── docker-compose.yml\n├── Dockerfile\n├── docs\n│  ├── docs.go\n│  ├── swagger.json\n│  └── swagger.yaml\n├── go.mod\n├── go.sum\n├── LICENSE\n├── Makefile\n├── pkg\n│  ├── api\n│  │  ├── books.go\n│  │  ├── books_test.go\n│  │  ├── router.go\n│  │  └── user.go\n│  ├── auth\n│  │  ├── auth.go\n│  │  └── auth_test.go\n│  ├── cache\n│  │  ├── cache.go\n│  │  ├── cache_mock.go\n│  │  └── cache_test.go\n│  ├── database\n│  │  ├── db.go\n│  │  ├── db_mock.go\n│  │  └── db_test.go\n│  ├── middleware\n│  │  ├── api_key.go\n│  │  ├── authenticateJWT.go\n│  │  ├── cors.go\n│  │  ├── rate_limit.go\n│  │  ├── security.go\n│  │  └── xss.go\n│  └── models\n│     ├── book.go\n│     └── user.go\n├── README.md\n├── scripts\n│  ├── generate_key\n│  └── generate_key.go\n└── vendor\n```\n\n## Getting Started\n\n### Prerequisites\n\n- Go 1.21+\n- Docker\n- Docker Compose\n\n### Installation\n\n1. Clone the repository\n\n```bash\ngit clone https://github.com/araujo88/golang-rest-api-template\n```\n\n2. Navigate to the directory\n\n```bash\ncd golang-rest-api-template\n```\n\n3. Build and run the Docker containers\n\n```bash\nmake up\n```\n\nPlease refer to the [Makefile](./Makefile) if you need to build in the local environment.\n\n### Environment Variables\n\nYou can set the environment variables in the `.env` file. Here are some important variables:\n\n- `POSTGRES_HOST`\n- `POSTGRES_DB`\n- `POSTGRES_USER`\n- `POSTGRES_PASSWORD`\n- `POSTGRES_PORT`\n- `JWT_SECRET`\n- `API_SECRET_KEY`\n\n### API Documentation\n\nThe API is documented using Swagger and can be accessed at:\n\n```\nhttp://localhost:8001/swagger/index.html\n```\n\n## Usage\n\n### Endpoints\n\n- `GET /api/v1/books`: Get all books.\n- `GET /api/v1/books/:id`: Get a single book by ID.\n- `POST /api/v1/books`: Create a new book.\n- `PUT /api/v1/books/:id`: Update a book.\n- `DELETE /api/v1/books/:id`: Delete a book.\n- `POST /api/v1/login`: Login.\n- `POST /api/v1/register`: Register a new user.\n\n### Authentication\n\nTo use authenticated routes, you must include the `Authorization` header with the JWT token.\n\n```bash\ncurl -H \"Authorization: Bearer \u003cYOUR_TOKEN\u003e\" http://localhost:8001/api/v1/books\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## End-to-End (E2E) Tests\n\nThis project contains end-to-end (E2E) tests to verify the functionality of the API. The tests are written in Python using the `pytest` framework.\n\n### Prerequisites\n\nBefore running the tests, ensure you have the following:\n\n- Python 3.x installed\n- `pip` (Python package manager)\n- The API service running locally or on a staging server\n- API key available\n\n### Setup\n\n#### 1. Create a virtual environment (optional but recommended):\n\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n#### 2. Install dependencies:\n\n```bash\npip install -r requirements.txt\n```\n\nThe main dependency is `requests`, but you may need to include it in your `requirements.txt` file if it's not already listed.\n\n#### 3. Set up the environment variables:\n\nYou need to set the `BASE_URL` and `API_KEY` as environment variables before running the tests.\n\nFor a **local** API service:\n\n```bash\nexport BASE_URL=http://localhost:8001/api/v1\nexport API_KEY=your-api-key-here\n```\n\nFor a **staging** server:\n\n```bash\nexport BASE_URL=https://staging-server-url.com/api/v1\nexport API_KEY=your-api-key-here\n```\n\nOn **Windows**, you can use:\n\n```bash\nset BASE_URL=http://localhost:8001/api/v1\nset API_KEY=your-api-key-here\n```\n\n#### 4. Run the tests:\n\nOnce the environment variables are set, you can run the tests using `pytest`:\n\n```bash\npytest test_e2e.py\n```\n\n### Test Structure\n\nThe tests will perform the following actions:\n\n1. Register a new user and obtain a JWT token.\n2. Create a new book in the system.\n3. Retrieve all books and verify the created book is present.\n4. Retrieve a specific book by its ID.\n5. Update the book's details.\n6. Delete the book and verify it is no longer accessible.\n\nEach test includes assertions to ensure that the API behaves as expected.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaa-software-engineering%2Fgolang-rest-api-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaa-software-engineering%2Fgolang-rest-api-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaa-software-engineering%2Fgolang-rest-api-template/lists"}