{"id":37126393,"url":"https://github.com/cheeyeo/ginexample","last_synced_at":"2026-01-14T14:36:27.454Z","repository":{"id":230837829,"uuid":"661858777","full_name":"cheeyeo/ginexample","owner":"cheeyeo","description":"Simple Go lang web app using Gin and Mongodb","archived":false,"fork":false,"pushed_at":"2023-07-03T20:34:24.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-01T06:47:35.370Z","etag":null,"topics":["docker","docker-compose","golang","mongodb"],"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/cheeyeo.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}},"created_at":"2023-07-03T20:25:35.000Z","updated_at":"2024-04-01T06:47:38.075Z","dependencies_parsed_at":"2024-04-01T06:57:42.102Z","dependency_job_id":null,"html_url":"https://github.com/cheeyeo/ginexample","commit_stats":null,"previous_names":["cheeyeo/ginexample"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cheeyeo/ginexample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheeyeo%2Fginexample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheeyeo%2Fginexample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheeyeo%2Fginexample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheeyeo%2Fginexample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cheeyeo","download_url":"https://codeload.github.com/cheeyeo/ginexample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cheeyeo%2Fginexample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28423877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["docker","docker-compose","golang","mongodb"],"created_at":"2026-01-14T14:36:26.582Z","updated_at":"2026-01-14T14:36:27.446Z","avatar_url":"https://github.com/cheeyeo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### API + MONGO DB\n\nExample of building a simple API backend that uses mongodb as storage.\n\nIt was based on articles:\nhttps://dev.to/deeshath/rest-api-using-gogin-mongo-33i3\n\nhttps://go.dev/doc/tutorial/web-service-gin\n\n\nI extended the above by adding:\n\n* Running the service and mongodb in containers\n\n* Created Dockerfile and docker compose template to run both concurrently\n\n* Custom Dockerfile with multistage build to compile the final web artifact\n\nNote that the compiled artifact is a Gin server running in dev mode so as such its not suitable for production use only for learning.\n\n\n### Running it\n\nTo run locally:\n```\ngo mod download\n```\n\nTo use docker compose:\n```\ndocker compose build web\n\ndocker compose up\n```\n\nIf running the service and mongodb container separately, need to export the mongodb url as an environment variable:\n\nTo run mongodb container:\n```\ndocker run --rm --name some-mongo -v ./data:/data/db mongo\n```\n\n```\nMONGO_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' some-mongo)\n\nexport MONGO_URL=mongodb://${MONGO_IP}:27017\n```\n\n### How to interact with API\n\nThe api is a simple CRUD service for books.\n\nUse either curl or postman to make requests.\n\nTo create a new book:\n```\ncurl http://localhost:8080/books \\\n    --include \\\n    --header \"Content-Type: application/json\" \\\n    --request \"POST\" \\\n    --data '{\"Title\": \"Atomic Habits\",\"Author\": \"James Clear\"}'\n```\n\nTo view a book with id:\n```\ncurl http://localhost:8080/books/64a1be64fb71ba1f1a00b5d5\n```\n\nTo view all books:\n```\ncurl http://localhost:8080/books\n```\n\nTo update book with id:\n```\ncurl http://localhost:8080/books/64a3249454fbd70d922ba3f8 \\\n    --include \\\n    --header \"Content-Type: application/json\" \\\n    --request \"PATCH\" \\\n    --data '{\"Title\": \"Mickey 7\",\"Author\": \"Ashton Edward\"}'\n```\n\nTo delete book with id:\n```\ncurl http://localhost:8080/books/64a1be64fb71ba1f1a00b5d5 \\\n    --request \"DELETE\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheeyeo%2Fginexample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheeyeo%2Fginexample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheeyeo%2Fginexample/lists"}