{"id":20624700,"url":"https://github.com/goodhosts/hostsfile","last_synced_at":"2026-01-06T06:27:00.762Z","repository":{"id":42226212,"uuid":"234993602","full_name":"goodhosts/hostsfile","owner":"goodhosts","description":"Go package for interfacing with an OS hosts file","archived":false,"fork":false,"pushed_at":"2023-12-23T17:41:45.000Z","size":355,"stargazers_count":33,"open_issues_count":2,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-15T14:59:25.043Z","etag":null,"topics":["go","golang-library","golang-package","hosts","hosts-file","hosts-file-edit","hostsfile"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goodhosts.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":"2020-01-20T01:12:30.000Z","updated_at":"2025-02-11T16:26:26.000Z","dependencies_parsed_at":"2023-10-16T12:28:08.428Z","dependency_job_id":"5aa1cfa2-79f1-4bcc-a1a0-066411094a7a","html_url":"https://github.com/goodhosts/hostsfile","commit_stats":null,"previous_names":["goodhosts/pkg"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodhosts%2Fhostsfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodhosts%2Fhostsfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodhosts%2Fhostsfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodhosts%2Fhostsfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goodhosts","download_url":"https://codeload.github.com/goodhosts/hostsfile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094940,"owners_count":21211837,"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":["go","golang-library","golang-package","hosts","hosts-file","hosts-file-edit","hostsfile"],"created_at":"2024-11-16T13:05:45.573Z","updated_at":"2026-01-06T06:27:00.734Z","avatar_url":"https://github.com/goodhosts.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go package for working with a system's hostsfile\n[![codecov](https://codecov.io/gh/goodhosts/hostsfile/branch/main/graph/badge.svg?token=BJQH16QQEH)](https://codecov.io/gh/goodhosts/hostsfile)\n[![Go Reference](https://pkg.go.dev/badge/github.com/goodhosts/hostsfile.svg)](https://pkg.go.dev/github.com/goodhosts/hostsfile)\n\nReads the content of a file in the [hosts format](https://en.wikipedia.org/wiki/Hosts_(file)) into go structs for easy manipulation in go programs. When all changes are complete you can `Flush` the hosts file back to disk to save your changes. Supports an indexing system on both ips and hosts for quick management of large hosts files.    \n\n## Simple Usage\nSimple usage reading in your system's hosts file and adding an entry for the ip `192.168.1.1` and the host `my-hostname`\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\n\t\"github.com/goodhosts/hostsfile\"\n)\n\nfunc main() {\n    hosts, err := hostsfile.NewHosts()\n    if err != nil {\n        log.Fatal(err.Error())\n    }\n    if err := hosts.Add(\"192.168.1.1\", \"my-hostname\"); err != nil {\n        log.Fatal(err.Error())\n    }\n    if err := hosts.Flush(); err != nil {\n        log.Fatal(err.Error())\n    }\n}\n```\n\n### Other Usage\nRead in a hosts file from a custom location which is not the system default, this is useful for tests or systems with non-standard hosts file locations.\n```\nhosts, err := hostsfile.NewCustomHosts(\"./my-custom-hostsfile\")\n```\n\nUse `Add` to put an ip and host combination in the hosts file\n```\nerr := hosts.Add(\"192.168.1.1\", \"my-hostname\")\n```\n\n`Add` is variadic and can take multiple hosts to add for the same ip\n```\nerr := hosts.Add(\"192.168.1.1\", \"my-hostname\", \"another-hostname\")\n```\n\nUse `Remove` to drop an ip and host combination from the hosts file\n```\nerr := hosts.Remove(\"192.168.1.1\", \"my-hostname\")\n```\n\n`Remove` is variadic and can take multiple hosts to remove from the same ip\n```\nerr := hosts.Remove(\"192.168.1.1\", \"my-hostname\", \"another-hostname\")\n```\n\nFlush the hosts file changes back to disk\n```\nerr := hosts.Flush()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodhosts%2Fhostsfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodhosts%2Fhostsfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodhosts%2Fhostsfile/lists"}