Documentation
¶
Index ¶
- Variables
- type Hosts
- func (h *Hosts) Add(ip string, hosts ...string) error
- func (h *Hosts) AddRaw(raw ...string) error
- func (h *Hosts) Clean()
- func (h *Hosts) Clear()
- func (h *Hosts) CombineDuplicateIPs()
- func (h *Hosts) Flush() error
- func (h *Hosts) FlushWriter(wr io.Writer) error
- func (h *Hosts) Has(ip string, host string) bool
- func (h *Hosts) HasHostname(host string) bool
- func (h *Hosts) HasIP(ip string) bool
- func (h *Hosts) HasIp(ip string) booldeprecated
- func (h *Hosts) HostsPerLine(count int)
- func (h *Hosts) IsWritable() bool
- func (h *Hosts) Load() error
- func (h *Hosts) Remove(ip string, hosts ...string) error
- func (h *Hosts) RemoveByHostname(host string) error
- func (h *Hosts) RemoveByIP(ip string)
- func (h *Hosts) RemoveByIp(ip string) errordeprecated
- func (h *Hosts) RemoveDuplicateHosts()
- func (h *Hosts) RemoveDuplicateIps()deprecated
- func (h *Hosts) SortByIp()deprecated
- func (h *Hosts) SortHosts()
- func (h *Hosts) SortIPs()
- func (h *Hosts) String() string
- type HostsLine
- func (l *HostsLine) Combine(hostline HostsLine)deprecated
- func (l *HostsLine) HasComment() bool
- func (l *HostsLine) IsComment() bool
- func (l *HostsLine) IsMalformed() bool
- func (l *HostsLine) IsValid() bool
- func (l *HostsLine) RegenRaw()
- func (l *HostsLine) RemoveDuplicateHosts()
- func (l *HostsLine) SortHosts()
- func (l *HostsLine) String() string
- func (l *HostsLine) ToRaw() string
Constants ¶
This section is empty.
Variables ¶
var ( HostsPerLine = -1 // unlimited HostsFilePath = "/etc/hosts" )
Functions ¶
This section is empty.
Types ¶
type Hosts ¶
type Hosts struct {
Path string // Path to the location of the hosts file that will be loaded/flushed
Lines []HostsLine // Slice containing all the lines parsed from the hosts file
// contains filtered or unexported fields
}
Hosts represents hosts file with the path and parsed contents of each line
func NewCustomHosts ¶
NewCustomHosts return a new instance of Hosts using a custom hosts file path.
func (*Hosts) CombineDuplicateIPs ¶
func (h *Hosts) CombineDuplicateIPs()
CombineDuplicateIPs finds all duplicate ips and combines all their hosts into one line
func (*Hosts) Flush ¶
Flush writes to the file located at Path the contents of Lines in a hostsfile format
func (*Hosts) FlushWriter ¶
FlushWriter writes the contents of Lines in the hostsfile format to the given io.Writer
func (*Hosts) HasHostname ¶
HasHostname return a bool if hostname in hosts file.
func (*Hosts) HostsPerLine ¶
HostsPerLine checks all ips and if their host count is greater than count will split into multiple lines with max of count hosts per line
func (*Hosts) IsWritable ¶
IsWritable return true if hosts file is writable.
func (*Hosts) Load ¶
Load the hosts file from the Path into Lines, called by NewHosts() and Hosts.Flush() and you should not need to call this yourself.
func (*Hosts) Remove ¶
Remove takes an ip and an optional host(s), if only an ip is passed the whole line is removed when the optional hosts param is passed it will remove only those specific hosts from that ip
func (*Hosts) RemoveByHostname ¶
RemoveByHostname go through all lines and remove a hostname if it exists
func (*Hosts) RemoveByIP ¶
func (*Hosts) RemoveByIp
deprecated
func (*Hosts) RemoveDuplicateHosts ¶
func (h *Hosts) RemoveDuplicateHosts()
RemoveDuplicateHosts will check each line and remove hosts if they are the same
func (*Hosts) RemoveDuplicateIps
deprecated
func (h *Hosts) RemoveDuplicateIps()
Deprecated: RemoveDuplicateIps deprecated will be deprecated, use Combine
func (*Hosts) SortHosts ¶
func (h *Hosts) SortHosts()
SortHosts will go through each line and sort the hosts in alpha order
type HostsLine ¶
type HostsLine struct {
IP string // IP found at the beginning of the line
Hosts []string // Hosts split into a slice on the space char
Comment string // Contents of everything after the comment char in the line
Raw string // Raw contents of the line as parsed in or updated after changes
Err error // Used for error checking during parsing
}
HostsLine represents a line of the hosts file after being parsed into their respective parts
func NewHostsLine ¶
NewHostsLine takes a raw line as a string and parses it into a new instance of HostsLine e.g. "192.168.1.1 host1 host2 # comments"
func (*HostsLine) HasComment ¶
func (*HostsLine) IsMalformed ¶
func (*HostsLine) RemoveDuplicateHosts ¶
func (l *HostsLine) RemoveDuplicateHosts()
RemoveDuplicateHosts checks all hosts in a line and removes duplicates