types

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

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

	// ErrDefaultProfile when trying to edit default content
	ErrDefaultProfile = errors.New("'default' profile should not be handled by hostctl")

	// ErrNoContent when data to write is empty
	ErrNoContent = errors.New("no content to write")

	// ErrNotPresentIP when looking for an IP not contained in profile
	ErrNotPresentIP = errors.New("ip not present")

	// ErrUnknownNetworkID when you pass an invalid network ID to sync docker
	ErrUnknownNetworkID = errors.New("unknown network ID")

	// ErrInvalidIP when the IP is malformed
	ErrInvalidIP = errors.New("invalid ip")

	// ErrInvalidProfileHeader when the profile header is invalid
	ErrInvalidProfileHeader = errors.New("invalid format for profile header")
)
View Source
var (
	// DefaultColumns is the list of default columns to use when showing table list
	DefaultColumns = []string{"profile", "status", "ip", "domain"}

	// ProfilesOnlyColumns are the columns used for profile status list
	ProfilesOnlyColumns = []string{"profile", "status"}
)

nolint:gochecknoglobals

Functions

This section is empty.

Types

type Content

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

Content contains complete data of all profiles

type DefaultProfile

type DefaultProfile []*Row

DefaultProfile contains data for the default profile

func (DefaultProfile) Render

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

Render writes the default profile content to the given StringWriter

type Profile

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

Profile contains all data of a single profile

func (*Profile) AddRoute

func (p *Profile) AddRoute(route *Route)

AddRoute adds a single route to the profile

func (*Profile) AddRouteUniq

func (p *Profile) AddRouteUniq(route *Route)

AddRouteUniq adds a single route to the profile and removes duplicates

func (*Profile) AddRoutes

func (p *Profile) AddRoutes(routes []*Route)

AddRoutes adds a list of routes to the profile

func (*Profile) AddRoutesUniq

func (p *Profile) AddRoutesUniq(routes []*Route)

AddRoutesUniq adds non duplicated routes to a profile

func (*Profile) GetAllHostNames

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

GetAllHostNames returns all hostnames of the profile.

func (*Profile) GetHostNames

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

GetHostNames returns a list of all hostnames of the given ip.

func (*Profile) GetStatus

func (p *Profile) GetStatus() string

GetStatus returns a string value of ProfileStatus

func (*Profile) RemoveHostnames

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

RemoveHostnames removes multiple hostnames of a profile

func (*Profile) Render

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

Render writes the profile content to the given StringWriter

func (*Profile) String

func (p *Profile) String() string

String returns a string representation of the profile

type Renderer

type Renderer interface {
	AppendRow(row *Row)
	AddSeparator()
	Render() error
}

Renderer is the interface to render hosts file content

type Route

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

Route contains hostnames of all routes with the same IP

func NewRoute

func NewRoute(ip string, hostnames ...string) *Route

NewRoute creates an new Route

type Row

type Row struct {
	Comment string
	Profile string
	Status  string
	IP      string
	Host    string
}

Row represents a line for all output types

type Status

type Status string

Status represents the status of a Profile

const (
	// Enabled marks a profile active on your hosts file.
	Enabled Status = "on"
	// Disabled marks a profile not active on your hosts file.
	Disabled Status = "off"

	// Default is the name of the default profile
	Default = "default"
)

Jump to

Keyboard shortcuts

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