host

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProfileError = errors.New("'default' profile should not be handled by hostctl")

DefaultProfileError when trying to edit default content

View Source
var MissingDestError = errors.New("missing destination file")

MissingSourceError when trying to write to a file

View Source
var MissingDomainsError = errors.New("no domains provided")

MissingDomainsError when trying to set/add domains and none were given

View Source
var MissingProfileError = errors.New("missing profile name")

MissingProfileError when the profile is mandatory

View Source
var MissingSourceError = errors.New("missing source file")

MissingSourceError when trying to read from a file

Functions

func AddFromArgs added in v0.4.0

func AddFromArgs(opts *AddFromArgsOptions) error

func AddFromFile

func AddFromFile(opts *AddFromFileOptions) error

AddFromFile reads content from a file and adds it as a profile into your hosts file. If you pass reset=true it will delete all previous content of the profile.

func BackupFile

func BackupFile(src, dstPath string) (string, error)

BackupFile creates a copy of your hosts file to a new location with the date as extension

func Disable

func Disable(dst, profile string) error

Disable marks a profile as disable by commenting all hosts lines. The content remains on the file and can be enabled later.

func Enable

func Enable(dst, profile string) error

Enable marks a profile as enable by uncommenting all hosts lines making the routing work again.

func EnableLine

func EnableLine(line string) string

EnableLine removes the # comment marker of the line.

func IsDisabled

func IsDisabled(line string) bool

IsDisabled check if a line starts with a # comment marker.

func IsHostLine

func IsHostLine(line string) bool

IsHostLine checks if a line is a host line or a comment line.

func ListProfiles

func ListProfiles(src string, opts *ListOptions) error

ListProfiles shows a table with profile names status and routing information

func Read

func Read(r io.Reader, strict bool) (*hostFile, error)

Read returns hosts file content grouped by profiles. If you pass strict=true it would remove all comments.

func ReadFromArgs added in v0.4.0

func ReadFromArgs(domains []string, ip string) *hostFile

ReadFromArgs read arguments into a hostFile struct

func ReadHostFile

func ReadHostFile(file string) (*hostFile, error)

ReadHostFile open a file an read content into a hostFile struct

func ReadHostFileStrict

func ReadHostFileStrict(file string) (*hostFile, error)

ReadHostFileStrict open a file an read content into a hostFile struct. removes all comments.

func RemoveDomains added in v0.5.2

func RemoveDomains(dst, profile string, domains []string) error

RemoveDomains removes domains from a hosts file.

func RemoveProfile added in v0.5.2

func RemoveProfile(dst, profile string) error

RemoveProfile removes a profile from a hosts file.

func RestoreFile

func RestoreFile(src, dst string) error

RestoreFile overwrite content of a hosts file with the content of a backup.

func WriteToFile

func WriteToFile(f *os.File, h *hostFile) error

WriteToFile write hosts content to file

Types

type AddFromArgsOptions added in v0.4.0

type AddFromArgsOptions struct {
	Dst     string
	Profile string
	Reset   bool
	Domains []string
	IP      string
}

AddFromArgsOptions contains available options for adding from arguments.

type AddFromFileOptions added in v0.4.0

type AddFromFileOptions struct {
	Dst     string
	Profile string
	Reset   bool
	From    string
}

AddFromFileOptions contains available options for adding from file.

type ListOptions

type ListOptions struct {
	Profile string
}

ListOptions contains available options for listing.

Jump to

Keyboard shortcuts

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