hosts

package
v0.0.0-...-8a2913d Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 1

README

This is a goinstall-able mirror of modified code already published at:
http://git.nic.cz/redmine/projects/godns/repository/show/hosts

Online godoc documentation for this package (should be) available at:
http://gopkgdoc.appspot.com/pkg/github.com/cznic/dns/hosts

Documentation

Overview

Package hosts supports hosts formatted data (see also `man hosts`). Supported are conversions from a file or string to an internal representation and back to a string.

Index

Constants

This section is empty.

Variables

View Source
var Sys = "/etc/hosts" //TODO:LSB only

System hosts name

Functions

This section is empty.

Types

type Cfg

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

Cfg represents a hosts.File with a change/modification guard/handler. Methods of Cfg are synchronized; multiple goroutines may invoke them concurrently.

func NewCfg

func NewCfg(fname string, logger *dns.Logger) (c *Cfg, err error)

NewCfg returns a newly created Cfg with hosts.File initialized from file fname or an Error of any. It binds the contained hosts.File to fname and on any changes to the fname file the Cfg hosts.File is reloaded on access via Cfg.File().

func (*Cfg) File

func (c *Cfg) File() (f *File, changed bool, err error)

File returns a hosts.File from Cfg and an indicator of its source file has been changed/modificated compared to the last invocation of this function or an Error if any.

func (*Cfg) SetChanged

func (c *Cfg) SetChanged()

SetChanged forces next File() to handle modification of the wrapped hosts.File.

type File

type File []*FileItem

A File holds items found in a hosts file, e.g. '/etc/hosts'. See also hosts(5)

func (*File) Load

func (h *File) Load(fname string) (err error)

Load File from a hosts format file fname. Return an Error, if any.

func (*File) LoadString

func (h *File) LoadString(fname, s string) (err error)

Load File from a hosts format string s. Return an Error, if any.

func (*File) String

func (h *File) String() string

type FileItem

type FileItem struct {
	IP            net.IP   // Well, it's an IP address
	CanonicalName string   // Per specs canocalized hostname
	Aliases       []string // Possibly empty hostname's aliases list
}

An FileItem holds an item found in a hosts file, e.g. '/etc/hosts'. See also hosts(5)

func (*FileItem) String

func (i *FileItem) String() string

type GoCfg

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

GoCfg is a Cfg wrapped in a goroutine allowing for concurrent access.

func NewGoCfg

func NewGoCfg(fname string, logger *dns.Logger) (c *GoCfg, err error)

NewGoCfg returns a newly created GoCfg or an Error if any. It is assumed there will be only one/few GoCfg instance(s) in an application. The instance(s) and its associated goroutine(s) will never be released. This is by design in an atempt to avoid some possibly nasty races on finalization. The "impossible to release" doesn't apply when NewGoCfg returns an Error.

func (*GoCfg) File

func (c *GoCfg) File() (f *File, changed bool, err error)

File returns a File from GoCfg and an indicator if its source file has been changed/modificated compared to the last invocation of this function or an Error if any. Invocations of File are concurrent safe.

Jump to

Keyboard shortcuts

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