hosts

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbort = errors.New("abort") // used to abort an update

Functions

func Insert

func Insert(entries Mapping) error

func IsLocal

func IsLocal(host string) bool

func IsPrivate

func IsPrivate(host string) bool

func Match

func Match(root, needle string) (sub string, ok bool)

google.com, www.google.com -> www., true google.com, google.com -> "", true google.com, yahoo.com -> "", false

func MatchMap

func MatchMap[V any](m map[string]V, needle string) (root, sub string, val V)

func Range

func Range(v string, f func(root, sub string) bool) bool

"www.google.com" "" "google.com" "www." "com" "www.google."

func TestMap

func TestMap[V any](m map[string]V, needle string) (ok bool)

func UpdateSystemConfig

func UpdateSystemConfig(cb func(*Config) (err error)) error

Types

type Address

type Address = string

func Resolve

func Resolve(hostname Hostname) (Address, error)

type Config

type Config []EntryLine

func SystemConfig

func SystemConfig() (cfg Config, err error)

func (*Config) Equals

func (h *Config) Equals(other Config) bool

func (*Config) Insert

func (h *Config) Insert(data Mapping) (changed bool)

func (Config) MarshalText

func (h Config) MarshalText() ([]byte, error)

func (Config) Resolve

func (h Config) Resolve(host Hostname) (adr Address, ok bool)

func (Config) String

func (h Config) String() string

func (*Config) UnmarshalText

func (h *Config) UnmarshalText(data []byte) error

type EntryLine

type EntryLine struct {
	OriginalLine string
	Address      Address
	Hostnames    []Hostname
	Comment      string
}

func (EntryLine) Equals

func (h EntryLine) Equals(other EntryLine) bool

func (EntryLine) HasHost

func (h EntryLine) HasHost(host Hostname) bool

func (EntryLine) MarhalText

func (h EntryLine) MarhalText() ([]byte, error)

func (EntryLine) String

func (h EntryLine) String() string

func (*EntryLine) UnmarshalText

func (h *EntryLine) UnmarshalText(data []byte) error

type Hostname

type Hostname = string

type Mapping

type Mapping map[Hostname]Address

func ResolveAll

func ResolveAll(hostname []Hostname) (Mapping, error)

Jump to

Keyboard shortcuts

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