Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/b0ch3nski/go-hosts-file
Yet another Golang library for hosts file manipulation.
https://github.com/b0ch3nski/go-hosts-file
etc-hosts golang hosts hosts-file hostsfile
Last synced: 1 day ago
JSON representation
Yet another Golang library for hosts file manipulation.
- Host: GitHub
- URL: https://github.com/b0ch3nski/go-hosts-file
- Owner: b0ch3nski
- License: apache-2.0
- Created: 2024-02-04T21:03:17.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-02-04T21:10:18.000Z (9 months ago)
- Last Synced: 2024-06-21T15:35:22.158Z (5 months ago)
- Topics: etc-hosts, golang, hosts, hosts-file, hostsfile
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-hosts-file
[![license](https://img.shields.io/github/license/b0ch3nski/go-hosts-file)](LICENSE)
[![release](https://img.shields.io/github/v/release/b0ch3nski/go-hosts-file)](https://github.com/b0ch3nski/go-hosts-file/releases)
[![go.dev](https://pkg.go.dev/badge/github.com/b0ch3nski/go-hosts-file)](https://pkg.go.dev/github.com/b0ch3nski/go-hosts-file)
[![goreportcard](https://goreportcard.com/badge/github.com/b0ch3nski/go-hosts-file)](https://goreportcard.com/report/github.com/b0ch3nski/go-hosts-file)
[![issues](https://img.shields.io/github/issues/b0ch3nski/go-hosts-file)](https://github.com/b0ch3nski/go-hosts-file/issues)
[![sourcegraph](https://sourcegraph.com/github.com/b0ch3nski/go-hosts-file/-/badge.svg)](https://sourcegraph.com/github.com/b0ch3nski/go-hosts-file)Yet another Golang library for hosts file manipulation. Written for my own purposes but can be easily adopted for
multiple other use cases like merging hosts files, removing duplicates, validating, reverse lookups etc.## install
```
go get github.com/b0ch3nski/go-hosts-file
```## example
```go
hostsFile, _ := os.Open("/etc/hosts")h := hosts.New()
h.Read(hostsFile)
h.Add(netip.AddrFrom4([4]byte{8, 8, 8, 8}), "google.com")fmt.Print(&h)
fmt.Println(h.GetIP("localhost"))
fmt.Println(h.GetAlias(netip.AddrFrom4([4]byte{127, 0, 0, 1})))
```