Version: v0.0.0-...-ec3898e Latest Latest

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

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 9 Imported by: 0



Package parser provides an interface to parse line/file-entry from/to hosts-file.

var reader io.Reader

// ...

entrySet, err := Read(reader)

// ...

entrySet.AddEntry(hosts.NewEntry("", []string{""}))

// ...

var writer io.Writer

// ...

err := Write(entrySet, writer)



This section is empty.


View Source
var (
	InvalidLineError = errors.New("invalid line")


func Read

func Read(reader io.Reader) (entrySet hosts.EntrySet, err error)

Read reads the hosts file from the provided io.Reader and returns an EntrySet.

func ReadFromLine

func ReadFromLine(line string) (ent hosts.Entry, err error)

ReadFromLine convert a given string to hostsfile.Entry.

func TrimWhitespace

func TrimWhitespace(oneLine string) string

TrimWhitespace removes all whitespaces ([\t\n\f\r ]) from the beginning and end of the given string.

func Write

func Write(entrySet hosts.EntrySet, writer io.Writer) error

Write writes the EntrySet to a well formatted hosts file into io.Write.

func WriteToLine

func WriteToLine(ent hosts.Entry) (line string, err error)

WriteToLine converts a given hostsfile.Entry to etc/hosts line without line-separator.

func WriteWith

func WriteWith(entrySet hosts.EntrySet, writer io.Writer, formatter func(ent hosts.Entry) (line string, err error)) error

WriteWith writes all entries formatted with the provided formatter from the provided EntrySet into io.Write.


This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL