Documentation
¶
Index ¶
- Variables
- type Content
- type DefaultProfile
- type DockerOptions
- type File
- func (f *File) AddProfile(profile Profile) error
- func (f *File) AddRoutes(name, ip string, hostnames []string) error
- func (f *File) Backup(dst string) (string, error)
- func (f *File) Close()
- func (f *File) Disable(profiles []string) error
- func (f *File) DisableAll() error
- func (f *File) DisableOnly(profiles []string) error
- func (f *File) Enable(profiles []string) error
- func (f *File) EnableAll() error
- func (f *File) EnableOnly(profiles []string) error
- func (f *File) Flush() error
- func (f *File) GetDisabled() []string
- func (f *File) GetEnabled() []string
- func (f *File) GetProfile(name string) (*Profile, error)
- func (f *File) GetProfileNames() []string
- func (f *File) GetStatus(profiles []string) map[string]ProfileStatus
- func (f *File) List(opts *ListOptions)
- func (f *File) MergeProfiles(content *Content)
- func (f *File) ProfileStatus(opts *ListOptions)
- func (f *File) RemoveProfile(name string) error
- func (f *File) RemoveProfiles(profiles []string) error
- func (f *File) RemoveRoutes(name string, routes []string) (bool, error)
- func (f *File) ReplaceProfile(p Profile) error
- func (f *File) Restore(from string) error
- func (f *File) Toggle(profiles []string) error
- func (f *File) WriteTo(src string) error
- type ListOptions
- type Profile
- func (p *Profile) AddRoute(ip, hostname string)
- func (p *Profile) AddRoutes(ip string, hostnames []string)
- func (p *Profile) GetAllHostNames() ([]string, error)
- func (p *Profile) GetHostNames(ip string) ([]string, error)
- func (p *Profile) GetStatus() string
- func (p *Profile) RemoveRoutes(hostnames []string)
- func (p *Profile) Render(w io.StringWriter) error
- func (p *Profile) String() string
- type ProfileStatus
- type Route
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingProfile when the profile is mandatory ErrMissingProfile = errors.New("missing profile name") // ErrUnknownProfile when the profile is not present ErrUnknownProfile = errors.New("unknown profile name") // ErrDefaultProfileError when trying to edit default content ErrDefaultProfileError = errors.New("'default' profile should not be handled by hostctl") // ErrMissingDomainsError when trying to set/add domains and none were given ErrMissingDomainsError = errors.New("no domains provided") // ErrMissingDestError when trying to write to a file ErrMissingDestError = errors.New("missing destination file") // ErrMissingSourceError when trying to read from a file ErrMissingSourceError = errors.New("missing source file") // ErrSnapConfinement when trying to read files on snap installation ErrSnapConfinement = errors.New("can't use --from or --host-file. " + "Snap confinement restrictions doesn't allow to read other than /etc/hosts file") )
var DefaultColumns = []string{"profile", "status", "ip", "domain"}
DefaultColumns is the list of default columns to use when showing table list
var ProfilesOnlyColumns = []string{"profile", "status"}
ProfilesOnlyColumns are the columns used for profile status list
Functions ¶
This section is empty.
Types ¶
type Content ¶ added in v1.0.0
type Content struct {
DefaultProfile DefaultProfile
ProfileNames []string
Profiles map[string]*Profile
}
Content contains complete data of all profiles
type DefaultProfile ¶ added in v1.0.0
type DefaultProfile []*tableRow
DefaultProfile contains data for the default profile
func (DefaultProfile) Render ¶ added in v1.0.0
func (d DefaultProfile) Render(w io.StringWriter) error
Render writes the default profile content to the given StringWriter
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
}
File container to handle a hosts file
func NewFile ¶ added in v1.0.0
NewFile creates a new File from the given src on default OS filesystem
func (*File) AddProfile ¶ added in v1.0.0
AddProfile adds a profile to the list
func (*File) Backup ¶ added in v1.0.0
Backup creates a copy of your hosts file to a new location with the date as extension
func (*File) Disable ¶ added in v1.0.0
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
DisableAll marks all profiles as disable by commenting all hosts lines. The content remains on the file and can be enabled later.
func (*File) DisableOnly ¶ added in v1.0.8
DisableOnly marks profiles as disable and enable all other profiles
func (*File) Enable ¶ added in v1.0.0
Enable marks profiles as enable by uncommenting all hosts lines making the routing work again.
func (*File) EnableAll ¶ added in v1.0.0
EnableAll marks all profiles as enable by uncommenting all hosts lines making the routing work again.
func (*File) EnableOnly ¶ added in v1.0.0
EnableOnly marks profiles as enable and disable all other profiles
func (*File) GetDisabled ¶ added in v1.0.0
GetDisabled returns a list of profiles that are Enabled
func (*File) GetEnabled ¶ added in v1.0.0
GetEnabled returns a list of profiles that are Enabled
func (*File) GetProfile ¶ added in v1.0.0
GetProfile return a Profile from the list
func (*File) GetProfileNames ¶ added in v1.0.0
GetProfileNames return a list of all profile names
func (*File) GetStatus ¶ added in v1.0.0
func (f *File) GetStatus(profiles []string) map[string]ProfileStatus
GetStatus returns a map with the status of the given profiles
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
MergeProfiles joins new content with existing 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
RemoveProfile removes given profile from the list
func (*File) RemoveProfiles ¶ added in v1.0.0
RemoveProfiles removes given profiles from the list
func (*File) RemoveRoutes ¶ added in v1.0.0
RemoveRoutes removes route information from a given profile. also removes the profile if gets empty.
func (*File) ReplaceProfile ¶ added in v1.0.0
ReplaceProfile removes previous profile with same name and add new profile to the list
func (*File) Restore ¶ added in v1.0.0
Restore overwrite content of a hosts file with the content of a backup.
type ListOptions ¶
type ListOptions struct {
Profiles []string
Columns []string
RawTable bool
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
IPList []string
Routes map[string]*Route
}
Profile contains all data of a single profile
func NewProfileFromDocker ¶ added in v1.0.0
func NewProfileFromDocker(ctx context.Context, opts *DockerOptions) (*Profile, error)
NewProfileFromDocker creates a new profile from docker info
func NewProfileFromReader ¶ added in v1.0.0
NewProfileFromReader creates a new profile reading lines from a reader
func (*Profile) GetAllHostNames ¶ added in v1.0.0
GetAllHostNames returns all hostnames of the profile.
func (*Profile) GetHostNames ¶ added in v1.0.0
GetHostNames returns a list of all hostnames of the given ip.
func (*Profile) RemoveRoutes ¶ added in v1.0.0
RemoveRoutes removes multiple hostnames of a profile
type ProfileStatus ¶ added in v0.9.1
type ProfileStatus string
ProfileStatus represents the status of a Profile
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" // Default is the name of the default profile Default = "default" )