Add ReadRR function
This commit is contained in:
parent
d78647b17d
commit
0211c1663d
30
zscan.go
30
zscan.go
|
@ -84,23 +84,25 @@ type Token struct {
|
||||||
Error *ParseError // when an error occured, this is the specifics
|
Error *ParseError // when an error occured, this is the specifics
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRR parses the string s and returns the RR contained in there. If the string
|
// NewRR reads the RR contained in the string s. Only the first RR is returned.
|
||||||
// contains more than one RR, only the first is returned. If an error is detected
|
// The class defaults to IN and TTL defaults to DefaultTtl
|
||||||
// that error is returned.
|
|
||||||
// If the class is not specified, the IN class is assumed. If the TTL is not
|
|
||||||
// specified DefaultTtl is assumed.
|
|
||||||
func NewRR(s string) (RR, error) {
|
func NewRR(s string) (RR, error) {
|
||||||
t := make(chan Token)
|
|
||||||
if s[len(s)-1] != '\n' { // We need a closing newline
|
if s[len(s)-1] != '\n' { // We need a closing newline
|
||||||
t = ParseZone(strings.NewReader(s+"\n"), "")
|
return ReadRR(strings.NewReader(s+"\n"), "")
|
||||||
} else {
|
|
||||||
t = ParseZone(strings.NewReader(s), "")
|
|
||||||
}
|
}
|
||||||
r := <-t
|
return ReadRR(strings.NewReader(s), "")
|
||||||
if r.Error != nil {
|
}
|
||||||
return nil, r.Error
|
|
||||||
}
|
// Ioreader here, or filename?? TODO
|
||||||
return r.RR, nil
|
|
||||||
|
// ReadRR reads the RR contained in q. Only the first RR is returned.
|
||||||
|
// The class defaults to IN and TTL defaults to DefaultTtl
|
||||||
|
func ReadRR(q io.Reader, filename string) (RR, error) {
|
||||||
|
r := <-ParseZone(q, filename)
|
||||||
|
if r.Error != nil {
|
||||||
|
return nil, r.Error
|
||||||
|
}
|
||||||
|
return r.RR, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseZone reads a RFC 1035 zone from r. It returns each parsed RR or on error
|
// ParseZone reads a RFC 1035 zone from r. It returns each parsed RR or on error
|
||||||
|
|
Loading…
Reference in New Issue