{"id":51462646,"url":"https://github.com/its-asif/go-commerce","last_synced_at":"2026-07-06T07:01:26.495Z","repository":{"id":306411002,"uuid":"1025184594","full_name":"its-asif/go-commerce","owner":"its-asif","description":"a RESTful API for an E-commerce platform built with Go.","archived":false,"fork":false,"pushed_at":"2026-06-06T18:25:38.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T20:13:23.510Z","etag":null,"topics":["dockerized","golang","gorilla-mux","postgresql","redis-cache","swagger"],"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/its-asif.png","metadata":{"files":{"readme":"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-23T21:32:33.000Z","updated_at":"2026-06-06T18:25:42.000Z","dependencies_parsed_at":"2025-07-25T15:49:22.370Z","dependency_job_id":"456bb23c-a6d7-4f7b-b8ae-b9dd97992431","html_url":"https://github.com/its-asif/go-commerce","commit_stats":null,"previous_names":["its-asif/go-commerce"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/its-asif/go-commerce","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/its-asif%2Fgo-commerce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/its-asif%2Fgo-commerce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/its-asif%2Fgo-commerce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/its-asif%2Fgo-commerce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/its-asif","download_url":"https://codeload.github.com/its-asif/go-commerce/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/its-asif%2Fgo-commerce/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35180933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-06T02:00:07.184Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dockerized","golang","gorilla-mux","postgresql","redis-cache","swagger"],"created_at":"2026-07-06T07:01:25.419Z","updated_at":"2026-07-06T07:01:26.446Z","avatar_url":"https://github.com/its-asif.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GO Commerce API\r\n\r\nThis is a RESTful API for an E-commerce platform built with Go. It supports user authentication, product management, cart operations, order processing, and category management.\r\n\r\n## Features\r\n\r\n- User registration and login with JWT authentication\r\n- Admin and user roles\r\n- Product CRUD (Create, Read, Update, Delete)\r\n- Cart management (add, remove, view items)\r\n- Order checkout and history\r\n- Category management (admin only)\r\n- PostgresSQL database integration\r\n- Redis caching for improved performance\r\n- Caching for products, categories, user data, cart items, and orders\r\n- Swagger API Documentation\r\n\r\n## Project Structure\r\n\r\n- `handlers/` - HTTP handlers for API endpoints\r\n- `models/` - Data models\r\n- `middleware/` - Authentication and authorization middleware\r\n- `db/` - Database connection logic (PostgreSQL \u0026 Redis)\r\n- `config/` - Environment variable loading\r\n- `routes/` - API route definitions\r\n- `migrations/` - SQL migration files\r\n- `utils/` - Utility functions (JWT, hashing, redis_cache)\r\n\r\n## Prerequisites\r\n\r\n- [Docker](https://www.docker.com/get-started)\r\n- [Docker Compose](https://docs.docker.com/compose/)\r\n\r\n## Setup Instructions\r\n\r\n### 1. Clone the Repository\r\n\r\n```sh\r\ngit clone https://github.com/its-asif/go-commerce.git\r\ncd go-commerce\r\n```\r\n\r\n### 2. Configure Environment Variables\r\n\r\nCopy `.env.example` to `.env` and update the values if needed:\r\n\r\n```sh\r\ncp .env.example .env\r\n```\r\n\r\nEnvironment Variables:\r\n- `PORT`: The port the API will run on (default: 8000)\r\n- `JWT_SECRET`: Secret key for JWT token signing\r\n- `DB_URL`: PostgreSQL connection string\r\n- `REDIS_URL`: Redis connection URL (default: redis://localhost:6379)\r\n- `REDIS_PASSWORD`: Redis password (if required)\r\n- `REDIS_DB`: Redis database number (default: 0)\r\n\r\n### 3. Build and Run with Docker Compose\r\n\r\nThis will start the Go API server, PostgreSQL database, Redis cache, and run migrations automatically.\r\n\r\n```sh\r\ndocker-compose up --build\r\n```\r\n\r\nServices started:\r\n- **API Server**: Available at `http://localhost:8000`\r\n- **PostgreSQL**: Available at `localhost:5432` (internal to Docker network as `go_db`)\r\n- **Redis**: Available at `localhost:6379` (internal to Docker network as `redis`)\r\n\r\n### 4. Swagger API Documentation\r\n\r\nThe API includes Swagger documentation for all endpoints. After starting the server, you can access the Swagger UI at:\r\n\r\n```\r\nhttp://localhost:8000/swagger/index.html\r\n```\r\n\r\nSwagger provides an interactive interface to test and explore the API.\r\n\r\n### 5. Redis Caching\r\n\r\nThe application implements Redis caching for:\r\n- **Products**: Individual products cached for 5 minutes, all products for 10 minutes\r\n- **Categories**: All categories cached for 30 minutes\r\n- **User Data**: User login data cached for 15 minutes\r\n- **Cart Items**: User cart items cached for 5 minutes\r\n- **Orders**: User orders cached for 10 minutes\r\n\r\nCache keys are automatically invalidated when data is modified (create, update, delete operations).\r\n\r\n### 6. API Endpoints\r\n\r\n- `POST /auth/register` - Register a new user\r\n- `POST /auth/login` - Login and receive JWT token\r\n- `GET /api/products` - List all products (cached)\r\n- `GET /api/products/{id}` - Get single product (cached)\r\n- `POST /api/products` - Create product (admin only, invalidates cache)\r\n- `PUT /api/products/{id}` - Update product (admin only, invalidates cache)\r\n- `DELETE /api/products/{id}` - Delete product (admin only, invalidates cache)\r\n- `GET /api/categories` - List all categories (cached)\r\n- `POST /api/categories` - Create category (admin only, invalidates cache)\r\n- `GET /api/cart` - Get cart items (cached)\r\n- `POST /api/cart` - Add item to cart (authenticated, invalidates cache)\r\n- `DELETE /api/cart/{product_id}` - Remove item from cart (authenticated, invalidates cache)\r\n- `GET /api/orders` - Get user orders (cached)\r\n- `POST /api/orders/checkout` - Checkout cart (authenticated, invalidates cache)\r\n\r\n### 7. Stopping the Services\r\n\r\nPress `Ctrl+C` in the terminal or run:\r\n\r\n```sh\r\ndocker-compose down\r\n```\r\n\r\n## Database Migrations\r\n\r\nMigrations are automatically applied on startup using the `migrate` service in `docker-compose.yml`. Migration files are located in the [migrations/](migrations/) directory.\r\n\r\n## Performance Optimization\r\n\r\nThe application uses Redis caching to improve performance:\r\n- Frequently accessed data is cached to reduce database queries\r\n- Cache invalidation ensures data consistency\r\n- Different cache TTL (Time To Live) values based on data update frequency\r\n\r\n## API Testing\r\n\r\nYou can test the API using the public Postman collection:  \r\n[GO Commerce API Postman Collection](https://www.postman.com/nemoh3618/public-workspace/collection/u2bc35o/ego-commerce?action=share\u0026creator=31642937)\r\n\r\n---\r\n\r\n**Note:** For development without Docker, ensure you have Go, PostgreSQL, and Redis installed, set up your `.env` file, run migrations manually, and start the server with:\r\n\r\n```sh\r\ngo run main.go\r\n```\r\n\r\nMake sure Redis is running on your local machine:\r\n```sh\r\nredis-server\r\n```\r\n\r\n## Running Tests (unit)\r\n\r\nThis repository includes a set of unit tests implemented with the Go standard library. To run them and generate a coverage report:\r\n\r\n```sh\r\ngo test -v ./...\r\ngo test -coverprofile=coverage.out ./...\r\ngo tool cover -func=coverage.out\r\ngo tool cover -html=coverage.out  # optional: opens HTML report\r\n\r\nGet total coverage percentage (CLI)\r\n```bash\r\n# Run tests and print the overall percentage (human-readable)\r\ngo test -coverprofile=coverage.out ./... \u003e/dev/null \u0026\u0026 go tool cover -func=coverage.out | awk '/total:/{print $3}'\r\n\r\n# Focused coverage for specific packages (example)\r\ngo test -coverpkg=./handlers,./middleware,./utils,./config -coverprofile=coverage.out ./... \u003e/dev/null \u0026\u0026 \\\r\n\tgo tool cover -func=coverage.out | awk '/total:/{print $3}'\r\n\r\n# Get numeric value (no percent sign) into a shell variable\r\nCOV=$(go test -coverprofile=coverage.out ./... \u003e/dev/null \u0026\u0026 go tool cover -func=coverage.out | awk '/total:/{print $3}' | tr -d '%')\r\necho \"Coverage: $COV%\"\r\n```\r\n```\r\n\r\nSummary of current test run (automatically generated):\r\n\r\n- Wrote 24 unit tests across packages: `utils`, `middleware`, `handlers`, and `config`.\r\n- Current overall coverage: 34.0% (see `coverage.out` for details).\r\n\r\nNotes \u0026 next steps:\r\n- Many DB-related functions and the generated `docs` package are not covered by these unit tests. Reaching 70%+ overall coverage will require either introducing test helpers/mocks for the database and Redis, or adding more integration tests that run against a test Postgres/Redis instance.\r\n- If you want me to continue toward 70% coverage, I recommend allowing the addition of focused test libraries (`github.com/DATA-DOG/go-sqlmock` and `github.com/alicebob/miniredis`) to make DB and Redis testing reliable and fast.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fits-asif%2Fgo-commerce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fits-asif%2Fgo-commerce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fits-asif%2Fgo-commerce/lists"}