{"id":15187304,"url":"https://github.com/thoriqdharmawan/go-rest-api-gin","last_synced_at":"2026-02-14T00:37:23.376Z","repository":{"id":257442121,"uuid":"858227574","full_name":"thoriqdharmawan/go-rest-api-gin","owner":"thoriqdharmawan","description":"A REST API using Gin framework in Go, offering CRUD operations for products with MySQL integration.","archived":false,"fork":false,"pushed_at":"2024-09-16T16:20:28.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T09:08:20.269Z","etag":null,"topics":["gin","go","gorm","mysql","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/thoriqdharmawan.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":"2024-09-16T14:30:35.000Z","updated_at":"2024-09-16T16:24:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ccf69d2-4304-47fa-b7f7-a398d1059402","html_url":"https://github.com/thoriqdharmawan/go-rest-api-gin","commit_stats":null,"previous_names":["thoriqdharmawan/go-rest-api-gin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thoriqdharmawan/go-rest-api-gin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoriqdharmawan%2Fgo-rest-api-gin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoriqdharmawan%2Fgo-rest-api-gin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoriqdharmawan%2Fgo-rest-api-gin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoriqdharmawan%2Fgo-rest-api-gin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoriqdharmawan","download_url":"https://codeload.github.com/thoriqdharmawan/go-rest-api-gin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoriqdharmawan%2Fgo-rest-api-gin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29426213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T22:20:51.549Z","status":"ssl_error","status_checked_at":"2026-02-13T22:20:49.838Z","response_time":78,"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":["gin","go","gorm","mysql","rest-api"],"created_at":"2024-09-27T18:10:01.926Z","updated_at":"2026-02-14T00:37:23.342Z","avatar_url":"https://github.com/thoriqdharmawan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 Go REST API with Gin Framework\n\nThis project is a simple REST API built using the [Gin](https://gin-gonic.com/) framework in Go. It provides endpoints to manage products in a database, including operations for listing, retrieving, creating, updating, and deleting products.\n\n## ✨ Features\n\n- **CRUD Operations**: Create, Read, Update, and Delete products 📝\n- **MySQL Database Integration**: Uses GORM to connect and interact with a MySQL database 🗄️\n- **JSON-based API**: Responses are provided in JSON format 📦\n- **Auto-migration**: Automatically creates and updates the product table 🔄\n\n## 🛠️ Prerequisites\n\n- [Go](https://golang.org/dl/) version 1.23.1 or higher 🚀\n- MySQL Database 🗄️\n- (Optional) Docker for running MySQL locally 🐳\n\n## 📦 Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/thoriqdharmawan/go-rest-api-gin.git\n   cd go-rest-api-gin\n   ```\n\n2. Install the required Go modules:\n\n   ```bash\n   go mod tidy\n   ```\n\n3. Set up MySQL and create a database:\n\n   ```sql\n   CREATE DATABASE go_restapi_gin;\n   ```\n\n4. Update the MySQL connection string in `models/database.go`:\n   ```go\n   \"root:root@tcp(localhost:3306)/go_restapi_gin\"\n   ```\n   Replace `root:root` with your MySQL username and password.\n\n## 🚀 Usage\n\n1. Start the application:\n\n   ```bash\n   go run main.go\n   ```\n\n2. The API will be available at `http://localhost:8080` 🌐.\n\n## 📋 API Endpoints\n\n### 📄 List Products\n\n- **Endpoint**: `GET /api/products`\n- **Description**: Retrieve all products from the database.\n- **Response**:\n  ```json\n  [\n    {\n      \"id\": 1,\n      \"nama_product\": \"Product 1\",\n      \"deskripsi\": \"Description of Product 1\"\n    },\n    ...\n  ]\n  ```\n\n### 🔍 Get Product by ID\n\n- **Endpoint**: `GET /api/products/:id`\n- **Description**: Retrieve a specific product by its ID.\n- **Response**:\n  ```json\n  {\n    \"id\": 1,\n    \"nama_product\": \"Product 1\",\n    \"deskripsi\": \"Description of Product 1\"\n  }\n  ```\n\n### ➕ Create Product\n\n- **Endpoint**: `POST /api/products`\n- **Description**: Create a new product.\n- **Request Body**:\n  ```json\n  {\n    \"nama_product\": \"New Product\",\n    \"deskripsi\": \"New Product Description\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"id\": 2,\n    \"nama_product\": \"New Product\",\n    \"deskripsi\": \"New Product Description\"\n  }\n  ```\n\n### ✏️ Update Product\n\n- **Endpoint**: `PUT /api/products/:id`\n- **Description**: Update an existing product by its ID.\n- **Request Body**:\n  ```json\n  {\n    \"nama_product\": \"Updated Product\",\n    \"deskripsi\": \"Updated Description\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"id\": 1,\n    \"nama_product\": \"Updated Product\",\n    \"deskripsi\": \"Updated Description\"\n  }\n  ```\n\n### 🗑️ Delete Product\n\n- **Endpoint**: `DELETE /api/products`\n- **Description**: Delete a product from the database.\n- **Response**:\n  ```json\n  {\n    \"message\": \"Product deleted successfully\"\n  }\n  ```\n\n## 🛠️ Database Model\n\nThe product model used in this project:\n\n```go\ntype Product struct {\n    Id          int64  `gorm:\"primaryKey\" json:\"id\"`\n    NamaProduct string `gorm:\"type:varchar(300)\" json:\"nama_product\"`\n    Deskripsi   string `gorm:\"type:text\" json:\"deskripsi\"`\n}\n```\n\n## 📚 Dependencies\n\nThis project uses the following Go packages:\n\n- [Gin](https://github.com/gin-gonic/gin) v1.10.0: HTTP web framework.\n- [GORM](https://gorm.io/) v1.25.12: ORM for Go.\n- [Go MySQL Driver](https://github.com/go-sql-driver/mysql) v1.7.0: MySQL driver for Go.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoriqdharmawan%2Fgo-rest-api-gin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoriqdharmawan%2Fgo-rest-api-gin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoriqdharmawan%2Fgo-rest-api-gin/lists"}