{"id":37211460,"url":"https://github.com/celer/gin-geo","last_synced_at":"2026-01-15T00:04:34.578Z","repository":{"id":57628169,"uuid":"404437067","full_name":"celer/gin-geo","owner":"celer","description":"Geolocation middleware for Gin","archived":false,"fork":true,"pushed_at":"2021-09-08T21:51:51.000Z","size":26973,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-20T16:49:30.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"cjgiridhar/gin-geo","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/celer.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}},"created_at":"2021-09-08T17:28:10.000Z","updated_at":"2021-09-08T17:43:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/celer/gin-geo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/celer/gin-geo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fgin-geo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fgin-geo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fgin-geo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fgin-geo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/celer","download_url":"https://codeload.github.com/celer/gin-geo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fgin-geo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"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":[],"created_at":"2026-01-15T00:04:34.001Z","updated_at":"2026-01-15T00:04:34.567Z","avatar_url":"https://github.com/celer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-geo : Geo location middleware for [Gin](https://github.com/gin-gonic/gin)\n\n[![Build][Build-Status-Image]][Build-Status-Url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]\n\n## Project Context and Features\n\nDetecting the location of users visiting your website is useful for a variety of reasons. \n\n- You might want to display different content based on different languages for people from different countries OR \n- Display targeted information to visitors from different locations OR \n- You may have setup database shards and want user signups to go to appropriate database based on their geography\n\nWhatever your reasons, this middleware comes to your rescue!\n\n## Requirements\n\ngin-geo uses the following [Go](https://golang.org/) packages as\ndependencies:\n\n- github.com/gin-gonic/gin\n\n## Installation\n\nStep 1: Assuming you've installed Go and Gin, run this command to get the middleware:  \n```\n$ go get github.com/cjgiridhar/gin-geo\n```\n\n[OPTIONAL] Step 2: Download latest GeoLite2 City Database from Maxmind.\n```\n$ wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz\n$ gunzip GeoLite2-City.mmdb.gz  \n```\nOR\nCopy it from the gin-geo repository\n```\ncp github.com/cjgiridhar/gin-geo/example/GeoLite2-City.mmdb .\n```\n\n[OPTIONAL] Step 3: Make sure file path for mmdb file is at correct location.\nPlease place the file from where your program runs.\n\nIf you look at the [gin-geo](https://github.com/cjgiridhar/gin-geo/tree/master/example) sample code, \n```example.go``` is pointing to the database location from the package. Hence Step 2 and Step 3 are optional.\nIf you need to use the latest database, please follow Step 2 and point the database path correctly. \n\n## Usage\n\nmain.go\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\tgeo \"github.com/cjgiridhar/gin-geo\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n\tgin.SetMode(gin.ReleaseMode)\n\tr := gin.Default()\n\tr.Use(geo.Default(\"github.com/cjgiridhar/gin-geo/db/GeoLite2-City.mmdb\"))\n\tr.GET(\"/geo\", func(c *gin.Context) {\n\t\tgeoResponse, ok := c.Get(\"GeoResponse\")\n\t\tif ok {\n\t\t\tc.JSON(http.StatusOK, gin.H{\n\t\t\t\t\"geo\": geoResponse,\n\t\t\t})\n\t\t} else {\n\t\t\tc.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{\n\t\t\t\t\"detail\": \"Could not get geographical information\",\n\t\t\t})\n\t\t}\n\t})\n\tr.Run()\n}\n```\n\n## Run the demo\n\nYou need a request from the internet to see the middleware in action.\nFor this you will need a public URL for exposing your local web server. \n\nFollow the steps:\n- Create a ```main.go``` file and copy the contents as given in the Usage section.\n- Make sure GeoLite2-City.mmdb is placed in the same path as main.go. [OPTIONAL]\n- Run the demo as: ```go run main.go``` (This will run a local web server on port 8080).\n- Download ngrok and run ```./ngrok http 8080``` (This will generate public URL and expose local web server to the internet).\n- Browse the public URL obtained from step 2, say https://public.ngrok.io/geo, from your browser.\n\n## Sample Output\n\n```\n{\n\t\"geo\": {\n\t\t\"IPAddress\":\"151.236.26.140\",\n\t\t\"CityName\":\"Zurich\",\n\t\t\"StateCode\":\"Zurich\",\n\t\t\"CountryCode\":\"CH\",\n\t\t\"ContinentCode\":\"EU\",\n\t\t\"TimeZone\":\"Europe/Zurich\",\n\t\t\"ZipCode\":\"8048\",\n\t\t\"Latitude\":47.3667,\n\t\t\"Longitude\":8.55,\n\t\t\"Language\":\"de\",\n\t}\n}\n```\n\n## Server Logs\n\n```\n2020/03/18 09:54:36 Geo: Middleware duration 391.525µs\n\u0026{151.236.26.140 Zurich Zurich CH EU Europe/Zurich 8048 47.3667 8.55 de {0 }}\n[GIN] 2020/03/18 - 09:54:36 | 200 |     472.715µs |    151.236.26.140 | GET      \"/geo\"\n\n```\n\n## How can I use the middleware?\n\nBased on the above sample output, you can use the CountryCode or ContinentCode information to make meaningful decisions for the client.\n\nFor instance, if it's a EU country, you can create the account for the client on a server hosted in EU region as per GDPR requirements.\n\n\n## Thanks\n\nThis middleware uses Maxmind's GeoLite (https://www.maxmind.com/en/home) database to get geo information\nand used HTTP headers to get the IP Address and Language for the user.\n\n## Contact\n\nTechnobeans, https://technobeans.com\n\n[Build-Status-Url]: https://travis-ci.com/cjgiridhar/gin-geo\n[Build-Status-Image]: https://travis-ci.com/cjgiridhar/gin-geo.svg?branch=master\n[codecov-url]: https://codecov.io/gh/cjgiridhar/gin-geo\n[codecov-image]: https://codecov.io/gh/cjgiridhar/gin-geo/branch/master/graph/badge.svg\n[reportcard-url]: https://goreportcard.com/report/github.com/cjgiridhar/gin-geo\n[reportcard-image]: https://goreportcard.com/badge/github.com/cjgiridhar/gin-geo\n[godoc-url]: https://godoc.org/github.com/cjgiridhar/gin-geo\n[godoc-image]: https://godoc.org/github.com/cjgiridhar/gin-geo?status.svg\n[license-url]: http://opensource.org/licenses/MIT\n[license-image]: https://img.shields.io/npm/l/express.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Fgin-geo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceler%2Fgin-geo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Fgin-geo/lists"}