{"id":20931841,"url":"https://github.com/say8hi/go-rest-api","last_synced_at":"2026-01-27T10:35:38.224Z","repository":{"id":226183755,"uuid":"767498230","full_name":"say8hi/go-rest-api","owner":"say8hi","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-04T14:56:28.000Z","size":1331,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T01:35:44.497Z","etag":null,"topics":["golang","postgresql","rabbitmq","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/say8hi.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-05T12:01:26.000Z","updated_at":"2025-01-22T13:50:28.000Z","dependencies_parsed_at":"2024-03-06T10:30:57.207Z","dependency_job_id":"4ee3830b-44b0-4002-a1dd-411d703722bd","html_url":"https://github.com/say8hi/go-rest-api","commit_stats":null,"previous_names":["say8hi/go-api-test"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/say8hi/go-rest-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fgo-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fgo-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fgo-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fgo-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/say8hi","download_url":"https://codeload.github.com/say8hi/go-rest-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fgo-rest-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28812142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","postgresql","rabbitmq","rest-api"],"created_at":"2024-11-18T21:46:01.641Z","updated_at":"2026-01-27T10:35:38.219Z","avatar_url":"https://github.com/say8hi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go API Project\n![Logo](./logo.webp)\n\nThis repository contains a Go-based API project that demonstrates a structured approach to building a Go application using various technologies such as Docker, PostgreSQL, RabbitMQ, and testing strategies. The project is structured to support scalability and maintainability.\n\n- [Go API Project](#go-api-project)\n  - [Project Structure](#project-structure)\n  - [Technologies Used](#technologies-used)\n  - [Authentication Method](#authentication-method)\n    - [Hashing Utility](#hashing-utility)\n      - [Usage](#usage)\n  - [Setup and Running](#setup-and-running)\n  - [API Endpoints](#api-endpoints)\n      - [Unauthorized Endpoints](#unauthorized-endpoints)\n      - [Authorized Endpoints](#authorized-endpoints) \n  - [Application Usage Examples](#application-usage-examples)\n      - [Creating a User](#creating-a-user) \n      - [Creating a Category](#creating-a-category)\n      - [Creating a Product](#creating-a-product)\n  - [Testing](#testing)\n\n## Project Structure\n\nThe project is organized as follows:\n\n- `cmd/go-api-test`: Contains the entry point of the application.\n- `internal`: Houses the core logic of the application, including database interactions, handlers, middlewares, and models.\n- `services/datacollector`: A separate service for collecting data and interacting with RabbitMQ.\n- `tests`: Contains integration tests for the application.\n- `Dockerfile` and `docker-compose.yml`: For containerization and orchestration.\n- `go.mod` and `go.sum`: Go module files for managing dependencies.\n\n## Technologies Used\n\n- **Go**: The primary programming language for building the application.\n- **Docker and Docker Compose**: Used for containerizing the application and its services.\n- **PostgreSQL**: The database system for storing application data.\n- **RabbitMQ**: For asynchronous message queuing.\n- **Gorilla Mux**: A powerful URL router and dispatcher for matching incoming requests to their respective handler.\n\n## Authentication Method\n\nThe application utilizes an authentication mechanism that employs a combination of the username and password, concatenated in the format \"passwordusername\", and then hashed using the SHA-256 algorithm. This approach ensures enhanced security by storing only hashed versions of the credentials, thereby protecting sensitive user information.\n\n### Hashing Utility\n\nFor convenience, the application includes a hashing utility script located in the `utils/` directory, named `hashcli.go`. This script allows for easy generation of SHA-256 hashes of arbitrary strings, adhering to the application's authentication format.\n\n#### Usage\n\nTo hash a string, such as a concatenated password and username, use the following command with the compiled binary:\n\n```bash\nbin/hashcli -s \"passwordusername\"\n```\n\n## Setup and Running\n\nTo run this project, you need to have Docker and Docker Compose installed on your system. Follow these steps:\n\n1. Clone the repository to your local machine.\n```bash\ngit clone https://github.com/say8hi/go-api-test.git\n```\n2. Go into **go-api-test** folder:\n```bash\ncd go-api-test\n```\n3. Rename `.env.example` to `.env` and adjust the configuration according to your environment.\n```bash\nmv .env.example .env\n```\n4. Build and start the services with Docker Compose:\n```bash\ndocker-compose up -d --build\n```\nThis command will start all the required services, including the Go application, PostgreSQL, and RabbitMQ.\n\n## API Endpoints\n\nThe application exposes several RESTful endpoints divided into unauthorized (public) and authorized (secured) categories. Authorization is managed through a bearer token provided in the `Authorization` header.\n\n### Unauthorized Endpoints\n\n- **Users**\n  - `POST /users/create`: Create a new user.\n\n- **Categories**\n  - `GET /category/{id}`: Get a category by ID.\n  - `GET /category/`: Get all categories.\n\n- **Products**\n  - `GET /product/{id}`: Get a product by ID.\n  - `GET /category/{id}/products`: Get all products in a category.\n\n### Authorized Endpoints\n\n- **Categories**\n  - `POST /category/create`: Create a new category.\n  - `PATCH /category/{id}`: Update a category.\n  - `DELETE /category/{id}`: Delete a category.\n\n- **Products**\n  - `POST /product/create`: Create a new product.\n  - `PATCH /product/{id}`: Update a product.\n  - `DELETE /product/{id}`: Delete a product.\n\nUse the provided `curl` examples in the [Application Usage Examples](#application-usage-examples) section to interact with these endpoints.\n\n## Application Usage Examples\n\nBelow are examples of how to interact with the application using `curl`, a command-line tool for transferring data with URLs. These examples demonstrate user creation, category creation, and product creation through the application's API.\n\n### Creating a User\n\nTo create a new user, send a POST request with the username and password in JSON format:\n\n```bash\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"username\": \"username\", \"password\": \"pass\"}' http://0.0.0.0:8080/users/create\n```\n### Creating a Category\n\nTo create a new category, you must first authenticate using a valid token. Then, send a POST request with the category name and description:\n```bash\ncurl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer YOUR_TOKEN_HERE\" -d '{\"name\": \"new_category\", \"description\": \"desc\"}' http://0.0.0.0:8080/category/create\n```\nReplace YOUR_TOKEN_HERE with your actual authentication token.\n\n### Creating a Product\n\nSimilarly, to create a new product, use an authenticated POST request. Provide the product name, description, price, and associated categories in JSON format:\n```bash\ncurl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer YOUR_TOKEN_HERE\" -d '{\"name\": \"new_product\", \"description\": \"desc\", \"price\": 2.5, \"categories\": [\"new_category\"]}' http://0.0.0.0:8080/product/create\n```\nAgain, replace YOUR_TOKEN_HERE with your actual authentication token. This example assumes you have already created a category named \"new_category\" to which the product is being associated.\n\n## Testing\n\nTo run the integration tests:\n```bash\n./run_tests.sh\n```\nThis script will set up the test environment, run the tests, and tear down the environment afterwards.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsay8hi%2Fgo-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsay8hi%2Fgo-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsay8hi%2Fgo-rest-api/lists"}