-- import "github.com/ChrisWiegman/goodhosts/v4/pkg/goodhosts"
type Hosts struct {
Path string
Section string
FileLines []HostsLine
SectionLines []HostsLine
}
Represents a hosts file.
func NewHosts(sectionName string) (Hosts, error)
Return a new instance of Hosts
.
func IsComment(line string) bool
Return true
if the string is a comment.
func (h *Hosts) Add(ip, comment string, hosts ...string) error
Add an entry to the hosts file.
func (h Hosts) Flush() error
Flush any changes made to hosts file.
func (h Hosts) Has(ip string, host string, forceFile bool) bool
Return a bool if ip/host combo in hosts file.
func (h *Hosts) IsWritable() bool
Return true
if hosts file is writable.
func (h *Hosts) Load() error
Load the hosts file into l.Lines
. Load()
is called by
NewHosts()
and Hosts.Flush()
so you generally you won't need to call
this yourself.
func (h *Hosts) Remove(ip string, hosts ...string) error
Remove an entry from the hosts file.
type HostsLine struct {
IP string
Hosts []string
Comment string
Raw string
Err error
}
Represents a single line in the hosts file.
func NewHostsLine(raw string) HostsLine
Return a new instance of HostsLine
.