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.
go get github.com/b0ch3nski/go-hosts-file
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})))