parser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockStart = "#### hostfile >>>>>"
	BlockEnd   = "#### hostfile <<<<<"

	DisableIPPrefix     = "#[disable-ip]"
	DisableDomainPrefix = "#[disable-domain]"
)

Variables

This section is empty.

Functions

func FormatBlock

func FormatBlock(block *ManagedBlock) string

FormatBlock formats a ManagedBlock back to string including the marker lines.

func FormatEntry

func FormatEntry(entry *HostEntry) string

FormatEntry formats a single HostEntry back to a hosts file line.

func ValidDomain added in v1.5.3

func ValidDomain(s string) bool

ValidDomain checks if a string is a valid domain name for hosts file use.

func ValidIP added in v1.1.1

func ValidIP(s string) bool

ValidIP checks if a string is a valid IP address, including IPv6 with zone ID (e.g. fe80::1%lo0).

Types

type DisableType

type DisableType int
const (
	DisableNone   DisableType = iota
	DisableIP                 // entire line disabled
	DisableDomain             // single domain disabled
)

type HostEntry

type HostEntry struct {
	IP          string
	Domains     []string
	DisableType DisableType
}

HostEntry represents a single entry in the managed block. For normal and disable-ip entries: IP + Domains. For disable-domain entries: IP + Domains (single domain that was disabled).

func ParseLine

func ParseLine(line string) (*HostEntry, error)

ParseLine parses a single line from within the managed block. Returns nil entry and nil error for empty/comment lines that should be skipped.

type ManagedBlock

type ManagedBlock struct {
	Entries  []HostEntry
	Warnings []string
}

ManagedBlock holds all entries within the managed block, plus any lines that failed to parse (stored as warnings).

func ParseBlock

func ParseBlock(content string) *ManagedBlock

ParseBlock parses the content inside a managed block (without the marker lines).

Jump to

Keyboard shortcuts

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