{"id":15095879,"url":"https://github.com/hasithaishere/go-rest-api-with-postgresql","last_synced_at":"2026-02-08T11:02:37.631Z","repository":{"id":246795018,"uuid":"822210358","full_name":"hasithaishere/go-rest-api-with-postgresql","owner":"hasithaishere","description":"A Go REST API with PostgreSQL demonstrating CRUD operations and IP logging middleware using the Gin framework.","archived":false,"fork":false,"pushed_at":"2024-06-30T16:11:11.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T11:47:37.338Z","etag":null,"topics":["backend","crud","gin","go","ip-logger","middleware","postgresql","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hasithaishere.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-30T15:33:05.000Z","updated_at":"2025-06-21T07:03:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6e038da-553c-43eb-ab59-6f9f87c8458e","html_url":"https://github.com/hasithaishere/go-rest-api-with-postgresql","commit_stats":null,"previous_names":["hasithaishere/go-rest-api-with-postgresql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hasithaishere/go-rest-api-with-postgresql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasithaishere%2Fgo-rest-api-with-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasithaishere%2Fgo-rest-api-with-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasithaishere%2Fgo-rest-api-with-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasithaishere%2Fgo-rest-api-with-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hasithaishere","download_url":"https://codeload.github.com/hasithaishere/go-rest-api-with-postgresql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasithaishere%2Fgo-rest-api-with-postgresql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29228544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T09:43:19.170Z","status":"ssl_error","status_checked_at":"2026-02-08T09:42:55.556Z","response_time":57,"last_error":"SSL_read: 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":["backend","crud","gin","go","ip-logger","middleware","postgresql","rest-api"],"created_at":"2024-09-25T15:43:02.586Z","updated_at":"2026-02-08T11:02:32.623Z","avatar_url":"https://github.com/hasithaishere.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Go REST API with PostgreSQL\n\nThis is a sample Go REST API project that demonstrates how to perform CRUD operations on a `Product` resource using the Gin framework and PostgreSQL. The project also includes middleware for logging the IP address of incoming requests.\n\n## Project Structure\n\n```\ngo-rest-api\n│   main.go\n├───config\n│       config.go\n├───controllers\n│       product_controller.go\n├───middleware\n│       ip_logger.go\n├───models\n│       product.go\n│       database.go\n├───routes\n│       routes.go\n└───utils\n        response.go\n```\n\n## Features\n\n- Create, read, update, and delete products\n- Log IP addresses of incoming requests\n\n## Getting Started\n\n### Prerequisites\n\n- Go 1.20 or higher\n- PostgreSQL\n- Git\n- Docker (optional, for running PostgreSQL in a container)\n\n### Installation\n\n1. Clone the repository:\n\n   ```sh\n   git clone https://github.com/hasithaishere/go-rest-api-with-postgresql.git\n   cd go-rest-api\n   ```\n\n2. Install dependencies:\n\n   ```sh\n   go mod tidy\n   ```\n\n3. Set up PostgreSQL:\n\n   - **Option 1: Using Docker (Recommended)**\n     - Run PostgreSQL in a Docker container:\n\n       ```sh\n       docker run --name postgres-db -e POSTGRES_USER=your_db_user -e POSTGRES_PASSWORD=your_db_password -e POSTGRES_DB=your_db_name -p 5432:5432 -d postgres\n       ```\n\n     - Update the `.env` file with your PostgreSQL credentials:\n\n       ```env\n       DB_USER=your_db_user\n       DB_PASSWORD=your_db_password\n       DB_NAME=your_db_name\n       DB_HOST=localhost\n       DB_PORT=5432\n       ```\n\n   - **Option 2: Local PostgreSQL Installation**\n     - Create a new PostgreSQL database.\n     - Update the `.env` file with your PostgreSQL credentials:\n\n       ```env\n       DB_USER=your_db_user\n       DB_PASSWORD=your_db_password\n       DB_NAME=your_db_name\n       DB_HOST=your_db_host\n       DB_PORT=your_db_port\n       ```\n\n4. Create the `products` table in your PostgreSQL database:\n\n   ```sql\n   CREATE TABLE products (\n       id SERIAL PRIMARY KEY,\n       name VARCHAR(255) NOT NULL,\n       price INTEGER NOT NULL,\n       created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,\n       updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP\n   );\n   ```\n\n### Running the Application\n\n1. Start the application:\n\n   ```sh\n   go run main.go\n   ```\n\n2. The server will start on `http://localhost:8080`.\n\n### API Endpoints\n\n- **GET /products**: Retrieve all products\n- **POST /products**: Create a new product\n  - Request body: `{ \"name\": \"Sample Product\", \"price\": 100 }`\n- **GET /products/:id**: Retrieve a product by ID\n- **PUT /products/:id**: Update a product by ID\n  - Request body: `{ \"name\": \"Updated Product\", \"price\": 150 }`\n- **DELETE /products/:id**: Delete a product by ID\n\n### Example CURL Commands\n\n- **Create a product:**\n\n  ```sh\n  curl -X POST http://localhost:8080/products \\\n       -H \"Content-Type: application/json\" \\\n       -d '{\n             \"name\": \"Sample Product\",\n             \"price\": 100\n           }'\n  ```\n\n- **Get all products:**\n\n  ```sh\n  curl http://localhost:8080/products\n  ```\n\n- **Get a product by ID:**\n\n  ```sh\n  curl http://localhost:8080/products/1\n  ```\n\n- **Update a product by ID:**\n\n  ```sh\n  curl -X PUT http://localhost:8080/products/1 \\\n       -H \"Content-Type: application/json\" \\\n       -d '{\n             \"name\": \"Updated Product\",\n             \"price\": 150\n           }'\n  ```\n\n- **Delete a product by ID:**\n\n  ```sh\n  curl -X DELETE http://localhost:8080/products/1\n  ```\n\n### Middleware\n\nThe project includes a middleware that logs the IP address of incoming requests. The middleware is defined in `middleware/ip_logger.go` and is registered in the router setup in `routes/routes.go`.\n\n### License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasithaishere%2Fgo-rest-api-with-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasithaishere%2Fgo-rest-api-with-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasithaishere%2Fgo-rest-api-with-postgresql/lists"}