file

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source

Banner is the mark added to hosts file.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File container to handle a hosts file.

func NewFile

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

NewFile creates a new File from the given src on default OS filesystem.

func NewWithFs

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

NewWithFs creates a new File with src and an existing filesystem.

func (*File) AddProfile

func (f *File) AddProfile(p *types.Profile) error

AddProfile adds a profile to the list.

func (*File) AddRoute

func (f *File) AddRoute(name string, route *types.Route) error

AddRoute adds a single route information to a given profile.

func (*File) AddRoutes

func (f *File) AddRoutes(name string, routes []*types.Route) error

AddRoutes adds routes information to a given profile.

func (*File) Backup

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

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

func (*File) Close

func (f *File) Close()

Close closes the underlying file.

func (*File) Disable

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

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

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

DisableOnly marks profiles as disable and enable all other profiles.

func (*File) Enable

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

func (f *File) EnableAll() error

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

func (*File) EnableOnly

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

EnableOnly marks profiles as enable and disable all other profiles.

func (*File) Flush

func (f *File) Flush() error

Flush overwrite file with hosts info.

func (*File) GetDisabled

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

GetDisabled returns a list of profiles that are Enabled.

func (*File) GetEnabled

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

GetEnabled returns a list of profiles that are Enabled.

func (*File) GetProfile

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

GetProfile return a Profile from the list.

func (*File) GetProfileNames

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

GetProfileNames return a list of all profile names.

func (*File) GetStatus

func (f *File) GetStatus(profiles []string) map[string]types.Status

GetStatus returns a map with the status of the given profiles.

func (*File) List

func (f *File) List(r types.Renderer, opts *ListOptions)

List shows a table with profile names status and routing information.

func (*File) MergeFile

func (f *File) MergeFile(from *File)

MergeFile joins new content with existing content.

func (*File) MergeProfiles

func (f *File) MergeProfiles(profiles []*types.Profile)

MergeProfiles joins new profiles with existing content.

func (*File) ProfileStatus

func (f *File) ProfileStatus(r types.Renderer, profiles []string)

ProfileStatus shows a table only with profile names status.

func (*File) RemoveHostnames

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

RemoveHostnames removes route information from a given types. also removes the profile if it gets empty.

func (*File) RemoveProfile

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

RemoveProfile removes given profile from the list.

func (*File) RemoveProfiles

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

RemoveProfiles removes given profiles from the list.

func (*File) ReplaceProfile

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

ReplaceProfile removes previous profile with same name and add new profile to the list.

func (*File) Restore

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

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

func (*File) Toggle

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

Toggle alternates between enable and disable status of a types.

func (*File) WriteTo

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

WriteTo overwrite file with hosts info.

type ListOptions

type ListOptions struct {
	Renderer     types.Renderer
	Profiles     []string
	ProfilesOnly bool
	StatusFilter types.Status
}

ListOptions contains available options for listing.

Jump to

Keyboard shortcuts

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