host

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultColumns = []string{"profile", "status", "ip", "domain"}

DefaultColumns is the list of default columns to use when showing table list

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

View Source
var ProfilesOnlyColumns = []string{"profile", "status"}

ProfilesOnlyColumns are the columns used for profile status list

View Source
var UnknownProfileError = errors.New("unknown profile name")

UnknownProfileError when the profile is not present

Functions

func AddFromArgs added in v0.4.0

func AddFromArgs(opts *AddFromArgsOptions) error

func AddFromDocker added in v0.7.0

func AddFromDocker(ctx context.Context, opts *AddFromDockerOptions) 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 AddFromReader added in v0.6.0

func AddFromReader(reader io.Reader, opts *AddFromFileOptions) error

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 EnableOnly added in v0.8.0

func EnableOnly(dst, profile string) error

EnableOnly marks a profile as enable and disable all other profiles

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 Toggle added in v0.9.0

func Toggle(dst, profile string) error

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 AddFromDockerOptions added in v0.7.0

type AddFromDockerOptions struct {
	Dst     string
	Domain  string
	Profile string
	Watch   bool
	Docker  *DockerOptions
}

AddFromFileOptions contains available options for adding from file.

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 DockerOptions added in v0.7.0

type DockerOptions struct {
	Network     string
	ComposeFile string
	ProjectName string
	KeepPrefix  bool
}

DockerOptions contains parameters to sync with docker and docker-compose

type ListOptions

type ListOptions struct {
	Profile      string
	RawTable     bool
	Columns      []string
	ProfilesOnly bool
	StatusFilter ProfileStatus
}

ListOptions contains available options for listing.

type ProfileStatus added in v0.9.1

type ProfileStatus string
const (
	// Enabled marks a profile active on your hosts file.
	Enabled ProfileStatus = "on"
	// Disabled marks a profile not active on your hosts file.
	Disabled ProfileStatus = "off"
)

Jump to

Keyboard shortcuts

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