{"id":30250257,"url":"https://github.com/taedmonds/product-mgt-api","last_synced_at":"2026-05-19T07:04:50.857Z","repository":{"id":282415587,"uuid":"948509184","full_name":"taedmonds/product-mgt-api","owner":"taedmonds","description":"A RESTful API built with Go and Fiber for managing products and inventory.","archived":false,"fork":false,"pushed_at":"2025-03-14T14:15:52.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T23:59:14.273Z","etag":null,"topics":["docker","golang","sample-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/taedmonds.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}},"created_at":"2025-03-14T13:13:54.000Z","updated_at":"2025-03-25T04:11:41.000Z","dependencies_parsed_at":"2025-03-14T14:42:28.993Z","dependency_job_id":null,"html_url":"https://github.com/taedmonds/product-mgt-api","commit_stats":null,"previous_names":["terance-edmonds/product-mgt-api","taedmonds/product-mgt-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/taedmonds/product-mgt-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taedmonds%2Fproduct-mgt-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taedmonds%2Fproduct-mgt-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taedmonds%2Fproduct-mgt-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taedmonds%2Fproduct-mgt-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taedmonds","download_url":"https://codeload.github.com/taedmonds/product-mgt-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taedmonds%2Fproduct-mgt-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33205507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"online","status_checked_at":"2026-05-19T02:00:06.763Z","response_time":58,"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":["docker","golang","sample-api"],"created_at":"2025-08-15T09:18:16.951Z","updated_at":"2026-05-19T07:04:50.843Z","avatar_url":"https://github.com/taedmonds.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Product Management API\n\nA RESTful API built with Go and Fiber for managing products and inventory. This project provides endpoints to create, read, update, delete products, and adjust inventory levels, with data persistence in memory and initial data loaded from a JSON file.\n\n## Table of Contents\n- [Product Management API](#product-management-api)\n  - [Table of Contents](#table-of-contents)\n  - [Features](#features)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n  - [Configuration](#configuration)\n    - [Optional Configuration with `.env`](#optional-configuration-with-env)\n  - [Running the Application](#running-the-application)\n    - [Locally](#locally)\n    - [With Docker](#with-docker)\n  - [API Endpoints](#api-endpoints)\n    - [Example Usage](#example-usage)\n  - [Docker Deployment](#docker-deployment)\n  - [API Specification](#api-specification)\n\n## Features\n- **CRUD Operations**: Manage products with create, read, update, and delete operations.\n- **Inventory Management**: Adjust product stock quantities.\n- **In-Memory Storage**: Stores data in memory with initial data loaded from a JSON file.\n- **Configurable**: Uses environment variables for configuration (e.g., port, hostname, initial data path).\n- **Docker Support**: Containerized deployment with a multi-stage Dockerfile.\n\n## Prerequisites\n- **Go**: Version 1.23 or higher\n- **Docker**: For containerized deployment\n- **Git**: To clone the repository\n\n## Installation\n1. **Clone the Repository**:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd product-mgt-api\n   ```\n\n2. **Install Dependencies**:\n   ```bash\n   go mod download\n   ```\n\n3. **Prepare Initial Data**:\n   Create a `configs/initial_data.json` file in the project root with the following structure:\n   ```json\n   [\n       {\n           \"id\": \"12345\",\n           \"name\": \"Wireless Mouse\",\n           \"description\": \"A comfortable wireless mouse with ergonomic design.\",\n           \"price\": 25.99,\n           \"category\": \"Electronics\",\n           \"stock_quantity\": 150,\n           \"created_at\": \"2025-01-15T10:00:00Z\",\n           \"updated_at\": \"2025-03-01T08:00:00Z\"\n       },\n       {\n           \"id\": \"67890\",\n           \"name\": \"Bluetooth Speaker\",\n           \"description\": \"Portable Bluetooth speaker with high-quality sound.\",\n           \"price\": 49.99,\n           \"category\": \"Electronics\",\n           \"stock_quantity\": 85,\n           \"created_at\": \"2025-02-05T12:00:00Z\",\n           \"updated_at\": \"2025-03-01T08:30:00Z\"\n       }\n   ]\n   ```\n\n## Configuration\nThe application uses environment variables for configuration. You can set these variables directly or use a `.env` file (requires `godotenv` integration—see [Optional Configuration](#optional-configuration)).\n\n| Variable         | Description                     | Default Value               |\n| ---------------- | ------------------------------- | --------------------------- |\n| `HOSTNAME`       | Hostname for the API server     | `localhost`                 |\n| `PORT`           | Port for the API server         | `8080`                      |\n| `ENV`            | Environment (e.g., development) | `\"\"` (empty string)         |\n| `INIT_DATA_PATH` | Path to initial data JSON file  | `configs/initial_data.json` |\n\n### Optional Configuration with `.env`\nTo use a `.env` file:\n1. Install `godotenv`:\n   ```bash\n   go get github.com/joho/godotenv\n   ```\n2. Add to `config/config.go` (in an `init()` function):\n   ```go\n   import \"github.com/joho/godotenv\"\n   func init() {\n       if err := godotenv.Load(); err != nil {\n           log.Printf(\"Warning: No .env file found: %v\", err)\n       }\n   }\n   ```\n\n## Running the Application\n### Locally\n```bash\ngo run main.go\n```\n- The API will start on `http://localhost:8080` (or the configured `HOSTNAME` and `PORT`).\n- You’ll see: `API Running on port: 8080`.\n\n### With Docker\n1. **Build the Docker Image**:\n   ```bash\n   docker build -t product-api .\n   ```\n\n2. **Run the Container**:\n   ```bash\n   docker run -p 8080:8080 -e INIT_DATA_PATH=/app/configs/initial_data.json product-api\n   ```\n   - Maps port 8080 on the host to 8080 in the container.\n   - Sets `INIT_DATA_PATH` to match the file location in the image.\n\n3. **Verify**:\n   Check logs:\n   ```bash\n   docker logs \u003ccontainer-id\u003e\n   ```\n   Should show: `API Running on port: 8080`.\n\n## API Endpoints\n| Method | Endpoint                | Description               |\n| ------ | ----------------------- | ------------------------- |\n| GET    | `/products`             | List all products         |\n| POST   | `/products`             | Create a new product      |\n| GET    | `/products/{productId}` | Get a product by ID       |\n| PUT    | `/products/{productId}` | Update a product          |\n| DELETE | `/products/{productId}` | Delete a product          |\n| POST   | `/inventory/adjustment` | Adjust inventory quantity |\n\n### Example Usage\n**Get All Products**:\n```bash\ncurl -X GET 'http://localhost:8080/products'\n```\n\n**Create a Product**:\n```bash\ncurl -X POST 'http://localhost:8080/products' \\\n-H 'Content-Type: application/json' \\\n-d '{\"name\": \"Noise Cancelling Headphones\", \"description\": \"Over-ear headphones\", \"price\": 120.00, \"category\": \"Electronics\", \"stock_quantity\": 75}'\n```\n\n## Docker Deployment\nThe project uses a multi-stage Dockerfile for efficient builds:\n- **Build Stage**: Compiles the Go binary with `golang:1.23-alpine`.\n- **Runtime Stage**: Runs the binary in a minimal `alpine` image as a non-root user (UID 10014).\n\n**Dockerfile Highlights**:\n- Copies `configs/initial_data.json` to `/app/configs/` in the container.\n- Sets the working directory to `/app`.\n- Runs as a non-root user for security.\n\n**Build and Run**:\n```bash\ndocker build -t product-api .\ndocker run -p 8080:8080 -e INIT_DATA_PATH=/app/configs/initial_data.json product-api\n```\n\n## API Specification\nThe API is documented in OpenAPI 3.0 format. See [openapi.yaml](docs/openapi.yaml) for details.\n\n**Debugging**:\n- Check build output:\n  ```bash\n  docker build -t product-api --progress=plain --no-cache .\n  ```\n- View container logs:\n  ```bash\n  docker logs \u003ccontainer-id\u003e\n  ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaedmonds%2Fproduct-mgt-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaedmonds%2Fproduct-mgt-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaedmonds%2Fproduct-mgt-api/lists"}