From ca0df8a12674b992945210cf67cbf001226f7615 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 20 Jul 2015 17:44:08 +0200 Subject: Initial import --- rfc.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 rfc.go diff --git a/rfc.go b/rfc.go new file mode 100644 index 0000000..f608d0c --- /dev/null +++ b/rfc.go @@ -0,0 +1,76 @@ +package rfc + +import ( + "bytes" + "encoding/xml" + "io" + "io/ioutil" + "net/http" +) + +const ( + RFCIndex = "rfc-index.xml" + RFCURL = "http://www.rfc-editor.org/in-notes/" + RFCIndex +) + +type Index struct { + Entries []Entry `xml:"rfc-entry"` +} + +type Entry struct { + ID string `xml:"doc-id"` + Title string `xml:"title"` + Authors []string `xml:"author>name"` + Month string `xml:"date>month"` + Year string `xml:"date>year"` + Format string `xml:"format>file-format"` + Chars int `xml:"format>char-count"` + Pages int `xml:"format>page-count"` + Keywords []string `xml:"keywords>kw"` + Abstract string `xml:"abstract>p"` + Draft string `xml:"draft"` + Notes string `xml:"notes"` + Obsoletes []string `xml:"obsoletes>doc-id"` + ObsoletedBy []string `xml:"obsoleted-by>doc-id"` + Updates []string `xml:"updates>doc-id"` + UpdatedBy []string `xml:"updated-by>doc-id"` + IsAlso []string `xml:"is-also>doc-id"` + SeeAlso []string `xml:"see-also>doc-id"` + CurrentStatus string `xml:"current-status"` + PublicationStatus string `xml:"publication-status"` + Stream string `xml:"stream"` + Area string `xml:"area"` + Acronym string `xml:"wg_acronym"` + ErrataURL string `xml:"errata-url"` + Doi string `xml:"doi"` +} + +func Decode(r io.Reader) ([]Entry, error) { + i := Index{} + err := xml.NewDecoder(r).Decode(&i) + if err != nil { + return nil, err + } + return i.Entries, nil +} + +func Fetch() (io.Reader, error) { + resp, err := http.Get(RFCURL) + if err != nil { + return nil, err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return bytes.NewReader(body), nil +} + +func Open() (io.Reader, error) { + body, err := ioutil.ReadFile(RFCIndex) + if err != nil { + return nil, err + } + return bytes.NewReader(body), nil +} -- cgit v1.2.3