utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddEntry

func AddEntry(hostsFilePath, ip string, fqdn string) error

AddEntry adds an entry to the hosts file, skip if the entry pair already existed

func Contains

func Contains(slice []string, item string) bool

Contains checks if a slice contains a specific string

func EnsureHeader

func EnsureHeader(hostsFilePath string) error

EnsureHeader ensures the header line exists in the hosts file

func GetEntriesByHostname

func GetEntriesByHostname(hostsFilePath, fqdn string) ([]string, error)

GetEntriesByHostname returns all entries in the hosts file that contains the specified FQDN

func GetEntriesByIP

func GetEntriesByIP(hostsFilePath, ip string) ([]string, error)

GetEntriesByIP returns all entries in the hosts file that contains the specified IP address

func RemoveAllHostname

func RemoveAllHostname(hostsFilePath, fqdn string) error

RemoveAllHostname removes all entries with the specified FQDN from the hosts file

func RemoveAllIP

func RemoveAllIP(hostsFilePath, ip string) error

RemoveAllIP removes all entries with the specified IP from the hosts file

func RemoveEntry

func RemoveEntry(hostsFilePath, ip string, fqdn string) error

RemoveEntry removes an entry from the hosts file, skip if the entry pair does not exist

Types

type IPOrHost

type IPOrHost int
const (
	IP IPOrHost = iota
	HOST
	INVALID
)

func IsIPorHostEntry

func IsIPorHostEntry(input string) IPOrHost

IsIPorHostEntry checks if the input is an IP address or a host entry (hostname or FQDN)

Jump to

Keyboard shortcuts

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