parser

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

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

Documentation

Overview

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("192.168.15.15", []string{"hello.world.com"}))

// ...

var writer io.Writer

// ...

err := Write(entrySet, writer)

Index

Constants

This section is empty.

Variables

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

Functions

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.

Types

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