{"id":15784458,"url":"https://github.com/keinos/go-hostpital","last_synced_at":"2025-05-07T05:47:55.705Z","repository":{"id":64940476,"uuid":"579567233","full_name":"KEINOS/go-hostpital","owner":"KEINOS","description":"A simple go library to maintain and manage hosts files for DNS sinkhole applications.","archived":false,"fork":false,"pushed_at":"2025-04-13T19:37:33.000Z","size":10701,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T20:34:39.039Z","etag":null,"topics":["go","golang","golang-library","hosts","hostsfile","parser"],"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/KEINOS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-18T05:33:33.000Z","updated_at":"2025-04-13T19:37:36.000Z","dependencies_parsed_at":"2023-11-07T12:23:12.573Z","dependency_job_id":"4d573e35-742e-40e0-a2af-cf3c770dc507","html_url":"https://github.com/KEINOS/go-hostpital","commit_stats":{"total_commits":66,"total_committers":3,"mean_commits":22.0,"dds":0.6363636363636364,"last_synced_commit":"d3312cce89f5ca6d74c3eb778aeaf80e57650d8f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KEINOS%2Fgo-hostpital","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KEINOS%2Fgo-hostpital/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KEINOS%2Fgo-hostpital/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KEINOS%2Fgo-hostpital/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KEINOS","download_url":"https://codeload.github.com/KEINOS/go-hostpital/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823687,"owners_count":21809708,"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","golang-library","hosts","hostsfile","parser"],"created_at":"2024-10-04T20:03:35.978Z","updated_at":"2025-05-07T05:47:55.682Z","avatar_url":"https://github.com/KEINOS.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD001 MD041 MD050 MD033 --\u003e\n[![go1.24+](https://img.shields.io/badge/Go-1.24--latest-blue?logo=go)](https://github.com/KEINOS/go-hostpital/blob/main/.github/workflows/unit-tests.yml \"Supported versions\")\n[![Go Reference](https://pkg.go.dev/badge/github.com/KEINOS/go-hostpital.svg)](https://pkg.go.dev/github.com/KEINOS/go-hostpital/hostpital#section-documentation \"Read generated documentation of the package\")\n\n# go-hostpital\n\nA simple library written in `go` (golang) to maintain and manage `hosts` files.\n\n## Usage\n\n```go\ngo get \"github.com/KEINOS/go-hostpital\"\n```\n\n```go\nimport \"github.com/KEINOS/go-hostpital/hostpital\"\n\nfunc ExampleValidator() {\n    // Validator with default settings\n    validator := hostpital.NewValidator()\n\n    validator.AllowComment = true    // Allow comment lines in the hostfile.\n    validator.IDNACompatible = false // Want RFC 6125 2.2 compatibility. If true, IDNA2008 compatible.\n\n    // Validate a file\n    pathFile := filepath.Join(\"testdata\", \"hosts.txt\")\n\n    if validator.ValidateFile(pathFile) {\n        fmt.Println(\"The hostfile is valid.\")\n    }\n\n    // Output: The hostfile is valid.\n}\n```\n\n```go\nimport \"github.com/KEINOS/go-hostpital/hostpital\"\n\nfunc ExampleParser() {\n    // For the default settings, see the NewValidator() example.\n    parser := hostpital.NewParser()\n\n    // Set the IP address to use for all the hosts. Suitable for DNS sinkhole.\n    parser.UseIPAddress = \"0.0.0.0\"\n\n    // Parse a file to clean up\n    pathFile := filepath.Join(\"testdata\", \"hosts.txt\")\n\n    parsed, err := parser.ParseFile(pathFile)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Println(parsed)\n    // Output:\n    // 0.0.0.0 dummy1.example.com\n    // 0.0.0.0 dummy2.example.com\n    // 0.0.0.0 dummy3.example.com\n    // 0.0.0.0 dummy4.example.com\n    // 0.0.0.0 dummy5.example.com dummy6.example.com\n}\n```\n\n```go\nimport \"github.com/KEINOS/go-hostpital/hostpital\"\n\n// Various functions\nfunc Example() {\n    // Detects IPV4 and IPV6\n    fmt.Println(\"IsIPAddress(\\\"0.0.0.0\\\") --\u003e\", hostpital.IsIPAddress(\"0.0.0.0\"))\n    fmt.Println(\"IsIPAddress(\\\"::\\\") --\u003e\", hostpital.IsIPAddress(\"::\"))\n    fmt.Println(\"IsIPAddress(\\\"0.0.0.0.0\\\") --\u003e\", hostpital.IsIPAddress(\"0.0.0.0.0\"))\n\n    // True if host name is ready for registration. False if it is a raw punycode or not IDNA2008 compatible.\n    fmt.Println(\"IsIDNAComatible(\\\"xn--gpher-jua.com\\\") --\u003e\", hostpital.IsIDNAComatible(\"xn--gpher-jua.com\"))\n    fmt.Println(\"IsIDNAComatible(\\\"göpher.com\\\") --\u003e\", hostpital.IsIDNAComatible(\"göpher.com\"))\n\n    // ASCII/Punycode \u003c---\u003e Unicode conversion\n    hostASCII, err := hostpital.TransformToASCII(\"göpher.com\")\n    fmt.Println(\"TransformToASCII(\\\"göpher.com\\\") --\u003e\", hostASCII, err)\n\n    hostUnicode, err := hostpital.TransformToUnicode(\"xn--gpher-jua.com\")\n    fmt.Println(\"TransformToUnicode(\\\"xn--gpher-jua.com\\\") --\u003e\", hostUnicode, err)\n\n    // Trim a comment from a line\n    hostTrimmed, err := hostpital.TrimComment(\"127.0.0.0 localhost # this is a line comment\")\n    fmt.Println(\"TrimComments(\\\"127.0.0.0 localhost # this is a line comment\\\") ---\u003e\", hostTrimmed, err)\n\n    /* And more ... */\n\n    // Output:\n    // IsIPAddress(\"0.0.0.0\") --\u003e true\n    // IsIPAddress(\"::\") --\u003e true\n    // IsIPAddress(\"0.0.0.0.0\") --\u003e false\n    // IsIDNAComatible(\"xn--gpher-jua.com\") --\u003e true\n    // IsIDNAComatible(\"göpher.com\") --\u003e false\n    // TransformToASCII(\"göpher.com\") --\u003e xn--gpher-jua.com \u003cnil\u003e\n    // TransformToPunycode(\"xn--gpher-jua.com\") --\u003e göpher.com \u003cnil\u003e\n    // TrimComments(\"127.0.0.0 localhost # this is a line comment\") ---\u003e 127.0.0.0 localhost  \u003cnil\u003e\n}\n```\n\n- [View more examples](https://pkg.go.dev/github.com/KEINOS/go-hostpital/hostpital#pkg-examples) @ pkg.go.dev\n- For command line example usage, see [./cmd/hostpital](./cmd/hostpital)\n\n## Statuses\n\n[![UnitTests](https://github.com/KEINOS/go-hostpital/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/KEINOS/go-hostpital/actions/workflows/unit-tests.yml)\n[![golangci-lint](https://github.com/KEINOS/go-hostpital/actions/workflows/golangci-lint.yml/badge.svg)](https://github.com/KEINOS/go-hostpital/actions/workflows/golangci-lint.yml)\n[![CodeQL-Analysis](https://github.com/KEINOS/go-hostpital/actions/workflows/codeQL-analysis.yml/badge.svg)](https://github.com/KEINOS/go-hostpital/actions/workflows/codeQL-analysis.yml)\n[![PlatformTests](https://github.com/KEINOS/go-hostpital/actions/workflows/platform-tests.yml/badge.svg)](https://github.com/KEINOS/go-hostpital/actions/workflows/platform-tests.yml)\n\n[![codecov](https://codecov.io/gh/KEINOS/go-hostpital/branch/main/graph/badge.svg?token=IQKfPZPiU1)](https://codecov.io/gh/KEINOS/go-hostpital)\n[![Go Report Card](https://goreportcard.com/badge/github.com/KEINOS/go-hostpital)](https://goreportcard.com/report/github.com/KEINOS/go-hostpital)\n\n## Contributing\n\n[![go1.24+](https://img.shields.io/badge/Go-1.24--latest-blue?logo=go)](https://github.com/KEINOS/go-hostpital/blob/main/.github/workflows/unit-tests.yml \"Supported versions\")\n[![Go Reference](https://pkg.go.dev/badge/github.com/KEINOS/go-hostpital.svg)](https://pkg.go.dev/github.com/KEINOS/go-hostpital#section-documentation \"Read generated documentation of the app\")\n\n- Branch to PR: `main`\n- [CONTRIBUTING.md](https://github.com/KEINOS/go-hostpital/blob/main/.github/CONTRIBUTING.md)\n- [CIs](https://github.com/KEINOS/go-hostpital/actions) on PR/Push: `unit-tests` `golangci-lint` `codeQL-analysis` `platform-tests`\n- [Security policy](https://github.com/KEINOS/go-hostpital/blob/main/.github/SECURITY.md)\n\n## License/Copyright\n\n- [MIT License](https://github.com/KEINOS/go-hostpital/blob/main/LICENSE)\n  - Copyright [KEINOS and the Hostpital contributors](https://github.com/KEINOS/go-hostpital/graphs/contributors)\n- [BSD-3-Clause license](https://github.com/golang/go/blob/master/LICENSE)\n  - Copyright of [`Is_compatible_rfc6125.go` by The Go Authors](https://github.com/KEINOS/go-hostpital/blob/main/hostpital/Is_compatible_rfc6125.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeinos%2Fgo-hostpital","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeinos%2Fgo-hostpital","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeinos%2Fgo-hostpital/lists"}