{"id":26533655,"url":"https://github.com/polunlin/go-gin-api","last_synced_at":"2026-05-04T11:32:46.059Z","repository":{"id":47538046,"uuid":"516178015","full_name":"PolunLin/go-gin-api","owner":"PolunLin","description":"go-gin-api","archived":false,"fork":false,"pushed_at":"2022-07-21T02:52:58.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T19:19:05.840Z","etag":null,"topics":["gin-gonic","go","golang"],"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/PolunLin.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}},"created_at":"2022-07-21T00:53:01.000Z","updated_at":"2022-07-21T08:27:16.000Z","dependencies_parsed_at":"2022-09-22T21:52:32.087Z","dependency_job_id":null,"html_url":"https://github.com/PolunLin/go-gin-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolunLin%2Fgo-gin-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolunLin%2Fgo-gin-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolunLin%2Fgo-gin-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PolunLin%2Fgo-gin-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PolunLin","download_url":"https://codeload.github.com/PolunLin/go-gin-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244852683,"owners_count":20521160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-gonic","go","golang"],"created_at":"2025-03-21T19:19:18.678Z","updated_at":"2025-10-16T05:02:06.437Z","avatar_url":"https://github.com/PolunLin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go-Gin-Api\n| This repo is for go gin api .\n\n\n## Table of contents\n- [Go-Gin-Api](#go-gin-api)\n  - [Table of contents](#table-of-contents)\n  - [How to Create](#how-to-create)\n  - [Repository Struct](#repository-struct)\n  - [Run the application](#run-the-application)\n  - [Result](#result)\n  - [Reference](#reference)\n## How to Create\n\n1. Create Database\n    ```bash\n    psql -U postgres # open psql CLI with user postgres\n    CREATE DATABASE go-gin-api;\n    \\l # list all databases\n    \\q #CLI exit\n    ```\n2. Clone the project\n    ```bash\n    git clone https://github.com/PolunLin/go-gin-api.git\n    cd go-gin-api\n    code .\n    go mod init github.com/YOUR_USERNAME/go-gin-api\n    ```\n3. Install Modules\n    ```\n    go get github.com/spf13/viper\n    go get github.com/gin-gonic/gin\n    go get gorm.io/gorm\n    go get gorm.io/driver/postgres\n    ```\n4. Environment Variable\n\n    in ``` common/envs/.env```\n    ```\n    PORT=:3000\n    DB_URL=postgres://DB_USER:DB_PASSWORD@DB_HOST:DB_PORT/go-gin-api\n    ```\n\n## Repository Struct\n\n```bash\n    tree /f\n    go-gin-api\n    │  go.mod\n    │  go.sum\n    │  Makefile\n    │  README.MD\n    │\n    ├─cmd\n    │      main.go\n    │\n    └─pkg\n        ├─books\n        │      add_book.go\n        │      controller.go\n        │      delete_book.go\n        │      get_book.go\n        │      get_books.go\n        │      update_book.go\n        │\n        └─common\n            ├─config\n            │      config.go\n            │\n            ├─db\n            │      db.go\n            │\n            ├─envs\n            │      .env\n            │\n            └─models\n                    book.go\n```\n\n## Run the application\n```bash\n    make server # or \n    go run cmd/main.go\n```\n## Result\n1. POST:add a new Book\n    ```bash\n    curl --request POST \\\n    --url http://localhost:3000/books/ \\\n    --header 'Content-Type: application/json' \\\n    --data '{\n        \"title\": \"Book A\",\n        \"author\": \"Author\",\n        \"description\": \"Some cool description\"\n    }'\n    ```\n2. GET: Get All Books\n    ```bash\n    curl --request GET --url http://localhost:3000/books/\n    ```\n3. GET: Get Book by ID\n    ```bash\n    curl --request GET --url http://localhost:3000/books/1/\n    ```\n4. PUT: Update Book by ID\n    ```bash\n    curl --request PUT \\\n    --url http://localhost:3000/books/1/ \\\n    --header 'Content-Type: application/json' \\\n    --data '{\n    \"title\": \"Updated Book Name\",\n    \"author\": \"Another author\",\n    \"description\": \"Updated description\"\n    }'\n    ```\n5. DELETE: Delete Book by ID\n    ```bash\n    curl --request DELETE --url http://localhost:3000/books/1/\n    ```\n## Reference\n   1. https://betterprogramming.pub/build-a-scalable-api-in-go-with-gin-131af7f780c0\n   2. https://gin-gonic.com/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolunlin%2Fgo-gin-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolunlin%2Fgo-gin-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolunlin%2Fgo-gin-api/lists"}