ermos/hostsfile

View on GitHub
examples/edit-host/main.go

Summary

Maintainability
A
0 mins
Test Coverage
package main

import (
    "github.com/ermos/hostsfile"
)

func main() {
    hosts, err := hostsfile.LoadFromPath("../default.hosts")
    if err != nil {
        panic(err)
    }

    host, err := hosts.FindFromAddress("127.0.0.2")
    if err != nil {
        panic(err)
    }

    host.SetComment("This is a comment")
    host.AddHostName("world2.lc")

    if err = hosts.FlushToPath("./generated.hosts"); err != nil {
        panic(err)
    }
}