hostsfile

package module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 10 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HostsPerLine  = -1 // unlimited
	HostsFilePath = "/etc/hosts"
)

Functions

This section is empty.

Types

type Hosts

type Hosts struct {
	Path  string
	Lines []HostsLine
}

func NewCustomHosts

func NewCustomHosts(osHostsFilePath string) (Hosts, error)

NewCustomHosts return a new instance of “Hosts“ using a custom hosts file path.

func NewHosts

func NewHosts() (Hosts, error)

NewHosts return a new instance of “Hosts“ using the default hosts file path.

func (*Hosts) Add

func (h *Hosts) Add(ip string, hosts ...string) error

Add an entry to the hosts file.

func (*Hosts) Clean added in v0.0.5

func (h *Hosts) Clean()

Clean merge duplicate ips and hosts per ip

func (Hosts) Flush

func (h Hosts) Flush() error

Flush any changes made to hosts file.

func (Hosts) Has

func (h Hosts) Has(ip string, host string) bool

Has return a bool if ip/host combo in hosts file.

func (Hosts) HasHostname

func (h Hosts) HasHostname(host string) bool

HasHostname return a bool if hostname in hosts file.

func (Hosts) HasIp

func (h Hosts) HasIp(ip string) bool

func (*Hosts) HostsPerLine added in v0.0.6

func (h *Hosts) HostsPerLine(count int)

func (*Hosts) IsWritable

func (h *Hosts) IsWritable() bool

IsWritable return ```true``` if hosts file is writable.

func (*Hosts) Load

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 (*Hosts) Remove

func (h *Hosts) Remove(ip string, hosts ...string) error

Remove an entry from the hosts file.

func (*Hosts) RemoveByHostname

func (h *Hosts) RemoveByHostname(host string) error

RemoveByHostname remove entries by hostname from the hosts file.

func (*Hosts) RemoveByIp

func (h *Hosts) RemoveByIp(ip string) error

func (*Hosts) RemoveDuplicateHosts added in v0.0.8

func (h *Hosts) RemoveDuplicateHosts()

func (*Hosts) RemoveDuplicateIps added in v0.0.5

func (h *Hosts) RemoveDuplicateIps()

func (*Hosts) SortByIp added in v0.0.6

func (h *Hosts) SortByIp()

SortByIp convert to net.IP and byte.Compare

func (*Hosts) SortHosts added in v0.0.8

func (h *Hosts) SortHosts()

type HostsLine

type HostsLine struct {
	IP      string
	Hosts   []string
	Raw     string
	Err     error
	Comment string
}

func NewHostsLine

func NewHostsLine(raw string) HostsLine

NewHostsLine return a new instance of ```HostsLine```.

func (*HostsLine) Combine added in v0.0.5

func (l *HostsLine) Combine(hostline HostsLine)

func (*HostsLine) HasComment added in v0.0.3

func (l *HostsLine) HasComment() bool

func (*HostsLine) IsComment

func (l *HostsLine) IsComment() bool

func (*HostsLine) IsMalformed

func (l *HostsLine) IsMalformed() bool

func (*HostsLine) IsValid

func (l *HostsLine) IsValid() bool

func (*HostsLine) RegenRaw

func (l *HostsLine) RegenRaw()

func (*HostsLine) RemoveDuplicateHosts added in v0.0.5

func (l *HostsLine) RemoveDuplicateHosts()

func (*HostsLine) SortHosts added in v0.0.5

func (l *HostsLine) SortHosts()

func (*HostsLine) ToRaw added in v0.0.3

func (l *HostsLine) ToRaw() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL