Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Latest commit

 

History

History
102 lines (74 loc) · 1.67 KB

API.md

File metadata and controls

102 lines (74 loc) · 1.67 KB

goodhosts

-- import "github.com/lextoumbourou/goodhosts"

Usage

type Hosts

type Hosts struct {
	Path  string
	Lines []HostsLine
}

Represents a hosts file.

func NewHosts

func NewHosts() (Hosts, error)

Return a new instance of Hosts using the default hosts file path.

func NewCustomHosts

func NewCustomHosts(customFilePath string) (Hosts, error)

Return a new instance of Hosts using a custom hosts file path.

func (*Hosts) Add

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

Add an entry to the hosts file.

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

Return a bool if ip/host combo in hosts file.

func (*Hosts) IsWritable

func (h *Hosts) IsWritable() bool

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.

type HostsLine

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

Represents a single line in the hosts file.

func NewHostsLine

func NewHostsLine(raw string) HostsLine

Return a new instance of HostsLine.

func (HostsLine) IsComment

func (l HostsLine) IsComment() bool

Return true if the line is a comment.