{"id":13704861,"url":"https://github.com/Massad/gin-boilerplate","last_synced_at":"2025-05-05T12:32:26.711Z","repository":{"id":37270325,"uuid":"55397574","full_name":"Massad/gin-boilerplate","owner":"Massad","description":"The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQL database and JWT authentication middleware stored in Redis","archived":false,"fork":false,"pushed_at":"2024-03-13T23:27:50.000Z","size":200,"stargazers_count":1070,"open_issues_count":9,"forks_count":192,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-11-05T04:02:31.399Z","etag":null,"topics":["boilerplate-template","database","gin-boilerplate","gin-framework","golang","jwt","microservices","middleware","postgresql","postman","postman-collection","redis","restful-api","ssl","trigger-functions"],"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/Massad.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":"2016-04-04T09:00:43.000Z","updated_at":"2024-11-02T09:08:57.000Z","dependencies_parsed_at":"2023-12-31T16:23:52.183Z","dependency_job_id":"a68e980d-9154-466a-b1ec-8d16231b2a64","html_url":"https://github.com/Massad/gin-boilerplate","commit_stats":{"total_commits":60,"total_committers":13,"mean_commits":4.615384615384615,"dds":0.7,"last_synced_commit":"5ad7e290e6dff18246af84227320034a5215f64a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Massad%2Fgin-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Massad%2Fgin-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Massad%2Fgin-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Massad%2Fgin-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Massad","download_url":"https://codeload.github.com/Massad/gin-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224197986,"owners_count":17271999,"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":["boilerplate-template","database","gin-boilerplate","gin-framework","golang","jwt","microservices","middleware","postgresql","postman","postman-collection","redis","restful-api","ssl","trigger-functions"],"created_at":"2024-08-02T22:00:21.598Z","updated_at":"2025-05-05T12:32:26.705Z","avatar_url":"https://github.com/Massad.png","language":"Go","funding_links":[],"categories":["Gin project in real world","GO","Go"],"sub_categories":[],"readme":"![alt tag](https://upload.wikimedia.org/wikipedia/commons/2/23/Golang.png)\n\n[![License](https://img.shields.io/github/license/Massad/gin-boilerplate)](https://github.com/Massad/gin-boilerplate/blob/master/LICENSE) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/Massad/gin-boilerplate)](https://github.com/Massad/gin-boilerplate/releases) [![Go Version](https://img.shields.io/github/go-mod/go-version/Massad/gin-boilerplate)](https://github.com/Massad/gin-boilerplate/blob/master/go.mod) [![DB Version](https://img.shields.io/badge/DB-PostgreSQL--latest-blue)](https://github.com/Massad/gin-boilerplate/blob/master/go.mod) [![DB Version](https://img.shields.io/badge/DB-Redis--latest-blue)](https://github.com/Massad/gin-boilerplate/blob/master/go.mod)\n\n[![Build Status](https://travis-ci.org/Massad/gin-boilerplate.svg?branch=master)](https://travis-ci.org/Massad/gin-boilerplate) [![Go Report Card](https://goreportcard.com/badge/github.com/Massad/gin-boilerplate)](https://goreportcard.com/report/github.com/Massad/gin-boilerplate)\n\n[![Join the chat at https://gitter.im/Massad/gin-boilerplate](https://badges.gitter.im/Massad/gin-boilerplate.svg)](https://gitter.im/Massad/gin-boilerplate?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nWelcome to **Golang Gin boilerplate** v2\n\nThe fastest way to deploy a restful api's with [Gin Framework](https://github.com/gin-gonic/gin/) with a structured project that defaults to **PostgreSQL** database and **JWT** authentication middleware stored in **Redis**\n\n## Configured with\n\n- [go-gorp](https://github.com/go-gorp/gorp): Go Relational Persistence\n- [jwt-go](https://github.com/golang-jwt/jwt): JSON Web Tokens (JWT) as middleware\n- [go-redis](https://github.com/go-redis/redis): Redis support for Go\n- Go Modules\n- Built-in **Custom Validators**\n- Built-in **CORS Middleware**\n- Built-in **RequestID Middleware**\n- Feature **PostgreSQL 12** with JSON/JSONB queries \u0026 trigger functions\n- SSL Support\n- Environment support\n- Unit test\n- And few other important utilties to kickstart any project\n\n### Installation\n\n```\n$ go get github.com/Massad/gin-boilerplate\n```\n\n```\n$ cd $GOPATH/src/github.com/Massad/gin-boilerplate\n```\n\n```\n$ go mod init\n```\n\n```\n$ go install\n```\n\nYou will find the **database.sql** in `db/database.sql`\n\nAnd you can import the postgres database using this command:\n\n```\n$ psql -U postgres -h localhost \u003c ./db/database.sql\n```\n\nTip:\n\nYou will find that we added 2 trigger functions to the dabatase:\n\n- `public.created_at_column()`\n- `public.update_at_column()`\n\nThose are added to the `updated_at` and `created_at` columns to update the latest timestamp automatically in both **user** and **article** tables. You can explore the tables and public schema for more info.\n\n## Running Your Application\n\nRename .env_rename_me to .env and place your credentials\n\n```\n$ mv .env_rename_me .env\n```\n\nGenerate SSL certificates (Optional)\n\n\u003e If you don't SSL now, change `SSL=TRUE` to `SSL=FALSE` in the `.env` file\n\n```\n$ mkdir cert/\n```\n\n```\n$ sh generate-certificate.sh\n```\n\n\u003e Make sure to change the values in .env for your databases\n\n```\n$ go run *.go\n```\n\n## Generate Swagger API Docs\n\n```\n$ make generate_docs\n```\n\n```\n$ make run\n```\n\n```\n$ open https://localhost:9000/swagger/index.html\n```\n\n## Building Your Application\n\n```\n$ go build -v\n```\n\n```\n$ ./gin-boilerplate\n```\n\n## Testing Your Application\n\n```\n$ go test -v ./tests/*\n```\n\n## Import Postman Collection (API's)\n\nDownload [Postman](https://www.getpostman.com/) -\u003e Import -\u003e Import From Link\n\nhttps://www.postman.com/collections/7f941b400a88ddd9c137\n\nIncludes the following:\n\n- User\n  - Login\n  - Register\n  - Logout\n- Article\n  - Create\n  - Update\n  - Get Article\n  - Get Articles\n  - Delete\n- Auth\n  - Refresh Token\n\n\u003e In Login request in Tests tab:\n\n```\npm.test(\"Status code is 200\", function () {\n    pm.response.to.have.status(200);\n\n    var jsonData = JSON.parse(responseBody);\n    pm.globals.set(\"token\", jsonData.token.access_token);\n    pm.globals.set(\"refresh_token\", jsonData.token.refresh_token);\n\n});\n```\n\nIt captures the `access_token` from the success login in the **global variable** for later use in other requests.\n\nAlso, you will find in each request that needs to be authenticated you will have the following:\n\n    Authorization -\u003e Bearer Token with value of {{token}}\n\nIt's very useful when you want to test the APIs in Postman without copying and pasting the tokens.\n\n## On You\n\nYou will need to implement the `refresh_token` mechanism in your application (Frontend).\n\n\u003e We have the `/v1/token/refresh` API here to use it.\n\n_For example:_\n\nIf the API sends `401` Status Unauthorized, then you can send the `refresh_token` that you stored it before from the Login API in POST `/v1/token/refresh` to receive the new `access_token` \u0026 `refresh_token` and store them again. Now, if you receive an error in refreshing the token, that means the user will have to Login again as something went wrong.\n\nThat's just an example, of course you can implement your own way.\n\n## Version 1\n\n    No longer supported\n\nYou will find the last update on v1 in [v1-session-cookies-auth](https://github.com/Massad/gin-boilerplate/tree/v1-session-cookies-auth) branch or [v1.0.5 release](https://github.com/Massad/gin-boilerplate/releases/tag/1.05) that supported the authentication using the **session** and **cookies** stored in **Redis** if needed.\n\n- [RedisStore](https://github.com/gin-gonic/contrib/tree/master/sessions): Gin middleware for session management with multi-backend support (currently cookie, Redis).\n\n## Contribution\n\nYou are welcome to contribute to keep it up to date and always improving!\n\nIf you have any question or need help, drop a message at [https://gitter.im/Massad/gin-boilerplate](https://gitter.im/Massad/gin-boilerplate)\n\n## Credit\n\nThe implemented JWT inspired from this article: [Using JWT for Authentication in a Golang Application](https://www.nexmo.com/blog/2020/03/13/using-jwt-for-authentication-in-a-golang-application-dr) worth reading it, thanks [Victor Steven](https://medium.com/@victorsteven)\n\n---\n\n## License\n\n(The MIT License)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMassad%2Fgin-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMassad%2Fgin-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMassad%2Fgin-boilerplate/lists"}