Documentation ¶
Overview ¶
Package resolvconf provides an interface to read, create and manipulate resolv.conf files
Example ¶
res, err := http.Get("https://gist.githubusercontent.com/turadg/7876784/raw/c7f2500fa4762cfe443e30c64c6ed8a888f6ac74/resolv.conf") if err != nil { log.Fatal(err) } conf, err := resolvconf.ReadConf(res.Body) if err != nil { log.Fatal(err) } res.Body.Close() conf.Remove(resolvconf.NewNameserver(net.ParseIP("8.8.4.4"))) conf.Add(resolvconf.NewDomain("foo.bar"), resolvconf.NewSortItem(net.ParseIP("130.155.160.0")).SetNetmask(net.ParseIP("255.255.240.0"))) conf.Write(os.Stdout)
Output: domain foo.bar nameserver 8.8.8.8 sortlist 130.155.160.0/255.255.240.0
Index ¶
- type Conf
- func (conf *Conf) Add(opts ...ConfItem) error
- func (conf *Conf) EnableLogging(writer io.Writer) error
- func (conf Conf) Find(o ConfItem) ConfItem
- func (conf *Conf) GetDomain() Domain
- func (conf *Conf) GetNameservers() []Nameserver
- func (conf *Conf) GetOptions() []Option
- func (conf *Conf) GetSearchDomains() []SearchDomain
- func (conf *Conf) GetSortItems() []SortItem
- func (conf *Conf) Remove(opts ...ConfItem) error
- func (conf *Conf) Write(w io.Writer) error
- type ConfItem
- type Domain
- type Nameserver
- type Option
- type SearchDomain
- type SortItem
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conf ¶
type Conf struct {
// contains filtered or unexported fields
}
Conf represents a configuration object
func ReadConf ¶
ReadConf will read a configuration from given io.Reader
Returns a new Conf object when successful otherwise nil and an error
func (*Conf) Add ¶
Add items to the configuration.
Errors are accumulated and can be reinterpreted as an multierror type. Logging will occur if logging has been setup using the EnableLogging call
Example ¶
conf := resolvconf.New() conf.Add(resolvconf.NewNameserver(net.ParseIP("8.8.8.8"))) conf.Write(os.Stdout)
Output: nameserver 8.8.8.8
Example (Second) ¶
conf := resolvconf.New() conf.Add(resolvconf.NewNameserver(net.ParseIP("8.8.8.8")), resolvconf.NewOption("debug")) conf.Write(os.Stdout)
Output: nameserver 8.8.8.8 options debug
func (*Conf) EnableLogging ¶
EnableLogging enables internal logging with given writer as output, currently only one writer is supported. conf will use LstdFlags for the logging
func (Conf) Find ¶
Find an configure item returns nil if item is not found. Returned will be a pointer to the actual item that can be converted into expected type
func (*Conf) GetNameservers ¶
func (conf *Conf) GetNameservers() []Nameserver
GetNameservers returns a list of all added nameservers
func (*Conf) GetOptions ¶
GetOptions returns a list of all added options
func (*Conf) GetSearchDomains ¶
func (conf *Conf) GetSearchDomains() []SearchDomain
GetSearchDomains returns a list of all added SearchDomains
func (*Conf) GetSortItems ¶
GetSortItems returns list of all added sortitems
func (*Conf) Remove ¶
Remove items from the configuration
Errors are accumulated and can be reinterpreted as an multierror type. Logging will occur if logging has been setup using the EnableLogging call
Example ¶
conf := resolvconf.New() ns := resolvconf.NewNameserver(net.ParseIP("8.8.8.8")) conf.Add(ns, resolvconf.NewNameserver(net.ParseIP("8.8.8.9"))) conf.Remove(ns) conf.Write(os.Stdout)
Output: nameserver 8.8.8.9
type ConfItem ¶
type ConfItem interface { fmt.Stringer Equal(b ConfItem) bool // contains filtered or unexported methods }
ConfItem is the generic interface all items in a resolv.conf file must implement.
type Domain ¶
type Domain struct {
Name string
}
Domain is the single domain in a resolv.conf file
func NewDomain ¶
NewDomain creates a new domain that will be used as value for the 'domain' option in the generated file
type Nameserver ¶
Nameserver is the nameserver type
func NewNameserver ¶
func NewNameserver(IP net.IP) *Nameserver
NewNameserver creates a new Nameserver item
func (Nameserver) Equal ¶
func (ns Nameserver) Equal(b ConfItem) bool
Equal compares to nameservers with eachother, returns true if equal
func (Nameserver) String ¶
func (ns Nameserver) String() string
type Option ¶
Option represents an option item which must have a Type and some options must have a value
func NewOption ¶
NewOption creates a new option, val must be a positive number if used. Witout val the option will be interpreted as a bolean e.g. debug , with a val the option will be interpreted as an setvalue, e.g. ndots:5
type SearchDomain ¶
type SearchDomain struct {
Name string
}
SearchDomain is one of the items in the search list
func NewSearchDomain ¶
func NewSearchDomain(dom string) *SearchDomain
NewSearchDomain creates a new search domain that will be added to the 'search' list in the generated file
func (SearchDomain) Equal ¶
func (sd SearchDomain) Equal(b ConfItem) bool
Equal compares two search domains with each other, returns true if equal
func (SearchDomain) String ¶
func (sd SearchDomain) String() string
type SortItem ¶
SortItem is one of the items in the sort list, it must have an address and may have an netmask
func NewSortItem ¶
NewSortItem creates a new sortlist that will be added to the 'sort' item in the resolv.conf file. If mask is given the output will be IP/mask e.g. 8.8.8.8/255.255.255.0 otherwise output will be IP only, e.g. 8.8.8.8
func (SortItem) GetNetmask ¶
GetNetmask returns netmask from an SortItems
func (*SortItem) SetNetmask ¶
SetNetmask sets the netmask for an SortItem