host

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 19 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

This section is empty.

Types

type Content added in v1.0.0

type Content struct {
	DefaultProfile DefaultProfile
	ProfileNames   []string
	Profiles       map[string]Profile
}

func Parse added in v1.0.0

func Parse(r io.Reader) (*Content, error)

Parse reads content from reader into Data struct.

type DefaultProfile added in v1.0.0

type DefaultProfile []*tableRow

func (DefaultProfile) Render added in v1.0.0

func (d DefaultProfile) Render(w io.StringWriter) error

type DockerOptions added in v0.7.0

type DockerOptions struct {
	Domain      string
	Network     string
	ComposeFile string
	ProjectName string
	KeepPrefix  bool
	Cli         *client.Client
}

DockerOptions contains parameters to sync with docker and docker-compose

type File added in v1.0.0

type File struct {
	// contains filtered or unexported fields
}

func NewFile added in v1.0.0

func NewFile(src string) (*File, error)

func NewWithFs added in v1.0.0

func NewWithFs(src string, fs afero.Fs) (*File, error)

func (*File) AddProfile added in v1.0.0

func (f *File) AddProfile(profile Profile) error

func (*File) AddRoutes added in v1.0.0

func (f *File) AddRoutes(name, ip string, hostnames []string) error

func (*File) Backup added in v1.0.0

func (f *File) Backup(dst string) (string, error)

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

func (*File) Close added in v1.0.0

func (f *File) Close()

func (*File) Disable added in v1.0.0

func (f *File) Disable(profiles []string) error

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

func (*File) DisableAll added in v1.0.0

func (f *File) DisableAll() error

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

func (*File) Enable added in v1.0.0

func (f *File) Enable(profiles []string) error

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

func (*File) EnableAll added in v1.0.0

func (f *File) EnableAll() error

EnableAll marks all profiles as enable by uncommenting all hosts lines making the routing work again.

func (*File) EnableOnly added in v1.0.0

func (f *File) EnableOnly(profiles []string) error

EnableOnly marks profiles as enable and disable all other profiles

func (*File) Flush added in v1.0.0

func (f *File) Flush() error

Flush overwrite file with hosts info

func (*File) GetDisabled added in v1.0.0

func (f *File) GetDisabled() []string

func (*File) GetEnabled added in v1.0.0

func (f *File) GetEnabled() []string

func (*File) GetProfile added in v1.0.0

func (f *File) GetProfile(name string) (*Profile, error)

func (*File) GetProfileNames added in v1.0.0

func (f *File) GetProfileNames() []string

func (*File) GetStatus added in v1.0.0

func (f *File) GetStatus(profiles []string) map[string]ProfileStatus

func (*File) List added in v1.0.0

func (f *File) List(opts *ListOptions)

List shows a table with profile names status and routing information

func (*File) MergeProfiles added in v1.0.0

func (f *File) MergeProfiles(content *Content)

func (*File) ProfileStatus added in v1.0.0

func (f *File) ProfileStatus(opts *ListOptions)

ProfileStatus shows a table only with profile names status

func (*File) RemoveProfile added in v1.0.0

func (f *File) RemoveProfile(name string) error

func (*File) RemoveProfiles added in v1.0.0

func (f *File) RemoveProfiles(profiles []string) error

func (*File) RemoveRoutes added in v1.0.0

func (f *File) RemoveRoutes(name string, routes []string) (bool, error)

func (*File) ReplaceProfile added in v1.0.0

func (f *File) ReplaceProfile(p Profile) error

func (*File) Restore added in v1.0.0

func (f *File) Restore(from string) error

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

func (*File) Toggle added in v1.0.0

func (f *File) Toggle(profiles []string) error

Toggle alternates between enable and disable status of a profile.

func (*File) WriteTo added in v1.0.0

func (f *File) WriteTo(src string) error

WriteTo overwrite file with hosts info

type ListOptions

type ListOptions struct {
	Profiles     []string
	RawTable     bool
	Columns      []string
	ProfilesOnly bool
	StatusFilter ProfileStatus
	Writer       io.Writer
}

ListOptions contains available options for listing.

type Profile added in v1.0.0

type Profile struct {
	Name   string
	Status ProfileStatus
	Routes map[string]*Route
}

func NewProfileFromDocker added in v1.0.0

func NewProfileFromDocker(ctx context.Context, opts *DockerOptions) (*Profile, error)

func NewProfileFromReader added in v1.0.0

func NewProfileFromReader(r io.Reader) (*Profile, error)

func (*Profile) AddRoute added in v1.0.0

func (p *Profile) AddRoute(ip, hostname string)

func (*Profile) AddRoutes added in v1.0.0

func (p *Profile) AddRoutes(ip string, hostnames []string)

func (*Profile) GetAllHostNames added in v1.0.0

func (p *Profile) GetAllHostNames() ([]string, error)

func (*Profile) GetHostNames added in v1.0.0

func (p *Profile) GetHostNames(ip string) ([]string, error)

func (*Profile) GetStatus added in v1.0.0

func (p *Profile) GetStatus() string

func (*Profile) RemoveRoutes added in v1.0.0

func (p *Profile) RemoveRoutes(hostnames []string)

func (*Profile) Render added in v1.0.0

func (p *Profile) Render(w io.StringWriter) error

func (*Profile) String added in v1.0.0

func (p *Profile) String() string

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"
)

type Route added in v1.0.0

type Route struct {
	IP        net.IP
	HostNames []string
}

Jump to

Keyboard shortcuts

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