hostsfile

package
v1.15.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package hostsfile has helpers for parsing a hosts file

Description: This file has the package hostfile.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

func New

func New(fileLocation, sectionName string) (*File, error)

New parses a hosts file and managed a block inside of the hosts file.

func NewWithContents

func NewWithContents(sectionName string, contents []byte) *File

func (*File) AddHosts

func (f *File) AddHosts(ipAddress string, hosts []string) error

AddHosts adds a line into the hosts file for the given hosts to resolve to specified IP. Any existing hosts are replaced.

func (*File) Load

func (f *File) Load(ctx context.Context) error

Load loads the hosts file into memory, and parses it.

func (*File) Marshal

func (f *File) Marshal(ctx context.Context) ([]byte, error)

Marshal renders a hosts file from memory.

func (*File) RemoveAddress

func (f *File) RemoveAddress(ipAddress string) error

RemoveAddress removes a given address and all hosts associated with it from the hosts file

func (*File) Save

func (f *File) Save(ctx context.Context) error

Save marshalls the hosts file and then saves it to disk.

type HostLine

type HostLine struct {
	Addresses []string
}

type Metadata

type Metadata struct {
	BlockName    string    `json:"blockName"`
	LastModified time.Time `json:"last_modified_at"`
}

Jump to

Keyboard shortcuts

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