{"id":15567669,"url":"https://github.com/circa10a/go-geofence","last_synced_at":"2025-10-02T22:30:21.876Z","repository":{"id":57635239,"uuid":"425880413","full_name":"circa10a/go-geofence","owner":"circa10a","description":"A small library to detect if an IP address is close to yours or another of your choosing using https://ipbase.com","archived":false,"fork":false,"pushed_at":"2024-07-21T01:26:37.000Z","size":40,"stargazers_count":18,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T22:29:31.024Z","etag":null,"topics":["geofence","geofence-api","geofencing","go","golang","golang-library","golang-package"],"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/circa10a.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":"2021-11-08T14:57:16.000Z","updated_at":"2024-07-21T01:26:40.000Z","dependencies_parsed_at":"2024-06-18T22:59:51.486Z","dependency_job_id":"79aa2575-500d-4123-aec2-aae4270feb6c","html_url":"https://github.com/circa10a/go-geofence","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/circa10a%2Fgo-geofence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/circa10a%2Fgo-geofence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/circa10a%2Fgo-geofence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/circa10a%2Fgo-geofence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/circa10a","download_url":"https://codeload.github.com/circa10a/go-geofence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235044589,"owners_count":18927112,"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":["geofence","geofence-api","geofencing","go","golang","golang-library","golang-package"],"created_at":"2024-10-02T17:12:17.119Z","updated_at":"2025-10-02T22:30:16.484Z","avatar_url":"https://github.com/circa10a.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-geofence\n\n![GitHub tag (latest semver)](https://img.shields.io/github/v/tag/circa10a/go-geofence?style=plastic)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/circa10a/go-geofence)](https://pkg.go.dev/github.com/circa10a/go-geofence?tab=overview)\n[![Go Report Card](https://goreportcard.com/badge/github.com/circa10a/go-geofence)](https://goreportcard.com/report/github.com/circa10a/go-geofence)\n\nA small library to detect if an IP address is close to yours or another of your choosing using https://ipbase.com/\n\n## Usage\n\nFirst you will need a free API Token from [ipbase.com](https://ipbase.com/)\n\n```bash\ngo get github.com/circa10a/go-geofence\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/circa10a/go-geofence\"\n)\n\nfunc main() {\n\tgeofence, err := geofence.New(\u0026geofence.Config{\n\t\t// Empty string to geofence your current public IP address, or you can monitor a remote address by supplying it as the first parameter\n\t\tIPAddress: \"\",\n\t\t// ipbase.com API token\n\t\tToken: \"YOUR_IPBASE_API_TOKEN\",\n\t\t// Maximum radius of the geofence in kilometers, only clients less than or equal to this distance will return true with IsIPAddressNear()\n\t\t// 1 kilometer\n\t\tRadius: 1.0,\n\t\t// Allow 192.X, 172.X, 10.X and loopback addresses\n\t\tAllowPrivateIPAddresses: true,\n\t\t// How long to cache if any ip address is nearby\n\t\tCacheTTL: 7 * (24 * time.Hour), // 1 week\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tisAddressNearby, err := geofence.IsIPAddressNear(\"8.8.8.8\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// Address nearby: false\n\tfmt.Println(\"Address nearby: \", isAddressNearby)\n}\n```\n\n## Caching\n\nTo cache keys indefinitely, set `CacheTTL: -1`\n\n### Local (in-memory)\n\nBy default, the library will use an in-memory cache that will be used to reduce the number of calls to ipbase.com and increase performance. If no `CacheTTL` value is set (`0`), the in-memory cache is disabled.\n\n### Persistent\n\nIf you need a persistent cache to live outside of your application, [Redis](https://redis.io/) is supported by this library. To have the library cache address proximity using a Redis instance, simply provide a `RedisOptions` struct using the `cache` package to `geofence.Config.RedisOptions`. If `RedisOptions` is configured, the in-memory cache will not be used.\n\n\u003e Note: Only Redis 7 is currently supported at the time of this writing.\n\n#### Example Redis Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/circa10a/go-geofence\"\n\tgeofencecache \"github.com/circa10a/go-geofence/cache\"\n)\n\nfunc main() {\n\tgeofence, err := geofence.New(\u0026geofence.Config{\n\t\tIPAddress: \"\",\n\t\tToken: \"YOUR_IPBASE_API_TOKEN\",\n\t\tRadius: 1.0,\n\t\tAllowPrivateIPAddresses: true,\n\t\tCacheTTL: 7 * (24 * time.Hour), // 1 week\n\t\t// Use Redis for caching\n\t\tRedisOptions: \u0026geofencecache.RedisOptions{\n\t\t\tAddr:     \"localhost:6379\",\n\t\t\tUsername: \"\", // no username set\n\t\t\tPassword: \"\", // no password set\n\t\t\tDB:       0,  // use default DB\n\t\t},\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tisAddressNearby, err := geofence.IsIPAddressNear(\"8.8.8.8\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Address nearby: false\n\tfmt.Println(\"Address nearby: \", isAddressNearby)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcirca10a%2Fgo-geofence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcirca10a%2Fgo-geofence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcirca10a%2Fgo-geofence/lists"}