Documentation ¶
Index ¶
- Variables
- func ConvertClassToString(i dns.Class) string
- func ConvertNumberToString[T constraints.Integer](def map[T]string, prefix string, i T) string
- func ConvertStringToClass(s string) (dns.Class, error)
- func ConvertStringToType(s string) (uint16, error)
- func ConvertToStringToNumber[T constraints.Integer](def map[string]T, prefix, s string) (T, error)
- func ConvertTypeToString(i uint16) string
- func Equals(a, b string) bool
- func GetAllParentNames(name string, level uint) ([]string, bool)
- func GetRDATA(rr dns.RR) string
- func GetRDATASlice(rrset RRSetInterface) []string
- func IsCompleteEqualsRRSet(a, b RRSetInterface) bool
- func IsENT(n NameNodeInterface) bool
- func IsEmptyRRSet(set RRSetInterface) bool
- func IsEqualsRRSet(a, b RRSetInterface) bool
- func IsHostname(name string) bool
- func MakeRR(r RRSetInterface, rdata string) (dns.RR, error)
- func MarshalJSONRRSet(set RRSetInterface) ([]byte, error)
- func RemoveNameNode(n NameNodeInterface, name string) error
- func SetNameNode(n, nn NameNodeInterface, generator NameNodeGenerator) error
- func SetRdata(set RRSetInterface, rdata []string) error
- type DefaultGenerator
- type Generator
- type NameNode
- func (n *NameNode) AddChildNameNode(nn NameNodeInterface) error
- func (n *NameNode) CopyChildNodes() map[string]NameNodeInterface
- func (n *NameNode) CopyRRSetMap() map[uint16]RRSetInterface
- func (n *NameNode) GetClass() dns.Class
- func (n *NameNode) GetName() string
- func (n *NameNode) GetNameNode(name string) (node NameNodeInterface, strict bool)
- func (n *NameNode) GetRRSet(rrtype uint16) RRSetInterface
- func (n *NameNode) IterateNameNode(f func(NameNodeInterface) error) error
- func (n *NameNode) IterateNameRRSet(f func(RRSetInterface) error) error
- func (n *NameNode) RRSetLen() int
- func (n *NameNode) RemoveChildNameNode(name string) error
- func (n *NameNode) RemoveRRSet(rrtype uint16) error
- func (n *NameNode) SetRRSet(set RRSetInterface) error
- func (n *NameNode) SetValue(nn NameNodeInterface) error
- type NameNodeGenerator
- type NameNodeInterface
- type RRSet
- func (r *RRSet) AddRR(rr dns.RR) error
- func (r *RRSet) Copy() RRSetInterface
- func (r *RRSet) GetClass() dns.Class
- func (r *RRSet) GetName() string
- func (r *RRSet) GetRRs() []dns.RR
- func (r *RRSet) GetRRtype() uint16
- func (r *RRSet) GetTTL() uint32
- func (r *RRSet) Len() int
- func (r *RRSet) MarshalJSON() ([]byte, error)
- func (r *RRSet) RemoveRR(rr dns.RR) error
- func (r *RRSet) SetTTL(ttl uint32) error
- func (r *RRSet) UnmarshalJSON(bs []byte) error
- type RRSetGenerator
- type RRSetInterface
- type Zone
- type ZoneInterface
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotSupport returns when method is not implemented. ErrNotSupport = fmt.Errorf("not support") // ErrNotChangeAble returns by change methods when can not change values. ErrNotChangeAble = fmt.Errorf("not changeable") )
var ( // ErrBadName returns when name is not domain name. ErrBadName = fmt.Errorf("bad name") // ErrNotDirectlyName returns by AddChildNode when arg node is not child name ErrNotDirectlyName = fmt.Errorf("add name's label count must be equals to parent label count +1") // ErrNotInDomain returns when arg node is in-domain. ErrNotInDomain = fmt.Errorf("name is not subdomain") // ErrChildExist returns when already exist arg node's name node. ErrChildExist = fmt.Errorf("child name is exist") // ErrNameNotEqual returns when arg name node's name is not equal. ErrNameNotEqual = fmt.Errorf("name not equals") // ErrClassNotEqual returns when arg name node's class is not equal. ErrClassNotEqual = fmt.Errorf("class not equals") // ErrConflictCNAME returns by SetRRSet when there is more than one SOA RDATA. ErrConflictCNAME = fmt.Errorf("name node can't set both CNAME and other") // ErrConflictDNAME returns by SetRRSet when there is more than one RDATA RDATA. ErrConflictDNAME = fmt.Errorf("name node can't set both DNAME and other") // ErrRemoveItself by RemoveChildNameNode when remove itself. ErrRemoveItself = fmt.Errorf("can not remove itself") )
var ( // ErrTTL returns when rrset's ttl and rr's ttl are not equals. ErrTTLNotEqual = fmt.Errorf("not equals ttl") // ErrRRType returns when rrset's rrtype and rr's rrtype are not equals. ErrRRTypeNotEqual = fmt.Errorf("not equals rrtype") // ErrConflict returns when there is more than one SOA RDATA or CNAME RDATA. ErrConflict = fmt.Errorf("conflict RR") // ErrInvalid returns when class or type is invalid format. ErrInvalid = fmt.Errorf("invalid data") // ErrFormat returns when input invalid format data. ErrFormat = fmt.Errorf("input format error") )
var ( // ErrRdata returns when rdata is invalid while parsing RDATA. ErrRdata = dns.ErrRdata // ErrNotTreeBroken returns tree is broken ErrNameTreeBroken = fmt.Errorf("name tree broken") )
Functions ¶
func ConvertClassToString ¶ added in v0.4.0
ConvertClassToString returns DNS Class string by dns.Class
func ConvertNumberToString ¶ added in v1.1.0
func ConvertNumberToString[T constraints.Integer](def map[T]string, prefix string, i T) string
func ConvertStringToClass ¶ added in v0.4.0
ConvertStringToClass returns dns.Class by string If it failed to parse, returns ErrInvalid
func ConvertStringToType ¶ added in v0.4.0
ConvertStringToType returns uint16 dns rrtype by string If it failed to parse, returns ErrInvalid
func ConvertToStringToNumber ¶ added in v1.1.0
func ConvertToStringToNumber[T constraints.Integer](def map[string]T, prefix, s string) (T, error)
func ConvertTypeToString ¶ added in v0.4.0
ConvertTypeToString returns RRType string by uint16 dns rrtype.
func GetAllParentNames ¶ added in v1.6.0
GetAllParentNames returns a name slice containing parent names and itself.
func GetRDATASlice ¶ added in v0.4.0
func GetRDATASlice(rrset RRSetInterface) []string
GetRDATASlice returns RDATA from rrset
func IsCompleteEqualsRRSet ¶ added in v0.2.2
func IsCompleteEqualsRRSet(a, b RRSetInterface) bool
IsCompleteEqualsRRSet check that both rrset equal.
func IsEmptyRRSet ¶
func IsEmptyRRSet(set RRSetInterface) bool
IsEmptyRRSet check that rrset is empty. if rrset is nil, it returns false. if radata is empty, return false. other than that return true.
func IsEqualsRRSet ¶
func IsEqualsRRSet(a, b RRSetInterface) bool
IsEqualsRRSet check that both rrset equal.However ttl value will be ignored.
func IsHostname ¶ added in v0.7.0
IsHostname checks if name is a valid RFC1123 hostname.
func MakeRR ¶
func MakeRR(r RRSetInterface, rdata string) (dns.RR, error)
MakeRR returns dns.RR by RRSet and rdata string
func MarshalJSONRRSet ¶ added in v0.4.0
func MarshalJSONRRSet(set RRSetInterface) ([]byte, error)
MarshalJSONRRset returns json.RawMessage by rrset.
func RemoveNameNode ¶ added in v0.4.0
func RemoveNameNode(n NameNodeInterface, name string) error
RemoveNameNode remove NameNodeInterface from tree.
func SetNameNode ¶ added in v0.4.0
func SetNameNode(n, nn NameNodeInterface, generator NameNodeGenerator) error
SetNameNode adds NameNode into tree. if not exist parent, create ENT NameNodeInterface by newFunc.s if exist same node, it overrides children and rrests.
func SetRdata ¶ added in v0.4.0
func SetRdata(set RRSetInterface, rdata []string) error
SetRdata set rdata into rrset
Types ¶
type DefaultGenerator ¶ added in v0.4.0
type DefaultGenerator struct{}
func (DefaultGenerator) NewNameNode ¶ added in v0.4.0
func (DefaultGenerator) NewNameNode(name string, class dns.Class) (NameNodeInterface, error)
func (DefaultGenerator) NewRRSet ¶ added in v0.4.0
func (DefaultGenerator) NewRRSet(name string, ttl uint32, class dns.Class, rrtype uint16) (RRSetInterface, error)
type Generator ¶ added in v0.4.0
type Generator interface { NameNodeGenerator RRSetGenerator }
type NameNode ¶
NameNode is implement of NameNodeInterface
func NewNameNode ¶
NewNameNode create NameNode
func (*NameNode) AddChildNameNode ¶ added in v0.4.0
func (n *NameNode) AddChildNameNode(nn NameNodeInterface) error
AddChildNameNode is implement of NameNodeInterface.AddChildNameNode
func (*NameNode) CopyChildNodes ¶
func (n *NameNode) CopyChildNodes() map[string]NameNodeInterface
CopyChildNodes is implement of NameNodeInterface.CopyChildNodes
func (*NameNode) CopyRRSetMap ¶
func (n *NameNode) CopyRRSetMap() map[uint16]RRSetInterface
CopyRRSetMap is implement of NameNodeInterface.CopyRRSetMap
func (*NameNode) GetNameNode ¶
func (n *NameNode) GetNameNode(name string) (node NameNodeInterface, strict bool)
GetNameNode is implement of NameNodeInterface.GetNameNode
func (*NameNode) GetRRSet ¶
func (n *NameNode) GetRRSet(rrtype uint16) RRSetInterface
GetRRSet is implement of NameNodeInterface.GetRRSet
func (*NameNode) IterateNameNode ¶
func (n *NameNode) IterateNameNode(f func(NameNodeInterface) error) error
IterateNameNode is implement of NameNodeInterface.IterateNameNode sort order using sort.StringSlice Sort.
func (*NameNode) IterateNameRRSet ¶
func (n *NameNode) IterateNameRRSet(f func(RRSetInterface) error) error
IterateNameRRSet is implement of NameNodeInterface.IterateNameRRSet first order is SOA. Other than, sort order by ASC.
func (*NameNode) RemoveChildNameNode ¶ added in v0.4.0
RemoveChildNameNode is implement of NameNodeInterface.AddChildNameNode
func (*NameNode) RemoveRRSet ¶
RemoveRRSet is implement of NameNodeInterface.RemoveRRSet
func (*NameNode) SetRRSet ¶
func (n *NameNode) SetRRSet(set RRSetInterface) error
SetRRSet is implement of NameNodeInterface.SetRRSet
func (*NameNode) SetValue ¶
func (n *NameNode) SetValue(nn NameNodeInterface) error
SetValue is implement of NameNodeInterface.SetValue
type NameNodeGenerator ¶ added in v0.4.0
type NameNodeGenerator interface {
NewNameNode(name string, class dns.Class) (NameNodeInterface, error)
}
type NameNodeInterface ¶
type NameNodeInterface interface { // GetName returns canonical name GetName() string // GetName returns class GetClass() dns.Class // GetNameNode returns NameNode by target name // if return value isStrict is true, NameNode is target name NameNode. (strict match) // if isStrict is false and node nos it nil, node is nearly parrent path node. (loose match) // if isStrict is false and node is nil, target name is not in-domain. GetNameNode(target string) (node NameNodeInterface, isStrict bool) // CopyChildNodes returns child name node map // map key is canonical name CopyChildNodes() map[string]NameNodeInterface // CopyRRSetMap returns rrset map // map key is uint16 rrtype CopyRRSetMap() map[uint16]RRSetInterface // GetRRSet returns rrset by rrtype // if not exist rrset return nil GetRRSet(rrtype uint16) RRSetInterface // IterateNameRRSet can iterate function by RRSetInterface // sort oreder is implementation dependent. IterateNameRRSet(func(RRSetInterface) error) error // IterateNameNode can iterate function by NameNodeInterface // sort oreder is implementation dependent. IterateNameNode(func(NameNodeInterface) error) error // AddChildNode adds child node into children. AddChildNameNode(NameNodeInterface) error // RemoveNameNode removed child node. RemoveChildNameNode(name string) error // SetValue override child and rrsetMap SetValue(NameNodeInterface) error // SetRRSet overrides rrset SetRRSet(RRSetInterface) error // RemoveRRSet removes rrset RemoveRRSet(rrtype uint16) error // RRSetLen returns the number of not empty rrset RRSetLen() int }
NameNodeInterface manages node of name tree
func GetNameNodeOrCreate ¶ added in v0.2.2
func GetNameNodeOrCreate(n NameNodeInterface, name string, generator NameNodeGenerator) (NameNodeInterface, error)
GetNameNodeOrCreate returns name node from arg name node. if exist NameNode, returns it. if not exist NameNode, It create new NameNode and return it. but new NameNode is not link to from arg name node. Maybe you can use SetNameNode.
type RRSet ¶
type RRSet struct {
// contains filtered or unexported fields
}
RRSet is implement of RRSetInterface
func NewRRSet ¶
func NewRRSet(name string, ttl uint32, class dns.Class, rrtype uint16, rrs []dns.RR) (*RRSet, error)
NewRRSet creates RRSet. Returns ErrBadName when name is not domain name
func NewRRSetFromRR ¶
NewRRSetFromRR creates RRSet from dns.RR If rr is nil return nil
func NewRRSetFromRRs ¶ added in v0.2.2
NewRRSetFromRRs creates RRSet from []dns.RR. It creates RRset by first RR using NewRRSetFromRR. 2nd and subsequent RR are add rrset using RRSet.AddRR. If RRSet.AddRR failed, return nil If rrs is nil return nil
func (*RRSet) AddRR ¶
AddRR add resource record rr is must equals al of name,ttl,class and rrtype. if duplicate RDATA, It will be ignored. It returns err when any of name, ttl, class and rrtype not equal. It returns err when rtype is SOA or CNAME, and it number is multiple.
func (*RRSet) MarshalJSON ¶ added in v0.4.0
MarshalJSON returns json.RawMessage.
func (*RRSet) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON reads rrset data from json.RawMessage.
type RRSetGenerator ¶ added in v0.4.0
type RRSetInterface ¶
type RRSetInterface interface { // GetName returns canonical name GetName() string // GetRRtype returns rrtype GetRRtype() uint16 // GetClass returns dns.Class GetClass() dns.Class // GetTTL returns rtype GetTTL() uint32 // SetTTL sets ttl SetTTL(uint32) error // GetRRs returns rr slice GetRRs() []dns.RR // Len returns number of rdata Len() int // AddRR adds dns.RR AddRR(dns.RR) error // RemoveRR removes dns.RR RemoveRR(dns.RR) error // Copy returns a copy Copy() RRSetInterface }
RRSetInterface manages rrset
func GetRRSetOrCreate ¶
func GetRRSetOrCreate(n NameNodeInterface, rrtype uint16, ttl uint32, generator RRSetGenerator) (RRSetInterface, error)
GetRRSetOrCreate returns rrset from name node. if exist rrset, returns it. if not exist rrset, It create new rrset and return it. but new rrset is not link to NameNode. Maybe you can use SetRRSet.
type Zone ¶
type Zone struct {
// contains filtered or unexported fields
}
Zone is implement of ZoneInterface
func (*Zone) GetGenerator ¶ added in v0.4.0
GetGenerator returns Generator
func (*Zone) GetRootNode ¶
func (z *Zone) GetRootNode() NameNodeInterface
GetRootNode returns zone apex NameNode If zone is not created by NewZone, maybe it returns nil
func (*Zone) MarshalJSON ¶ added in v0.4.0
MarshalJSON returns json.RawMessage.
func (*Zone) Read ¶
Read reads zone data from zonefile (RFC1035) It overrides zone's name and class when root node not exist.
func (*Zone) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON reads zone data from json.RawMessage. It override zone's name and class when root node not exist.
type ZoneInterface ¶
type ZoneInterface interface { // return canonical zone name GetName() string GetRootNode() NameNodeInterface GetClass() dns.Class }
ZoneInterface manages zone root node