summaryrefslogtreecommitdiff
path: root/rfc.go
diff options
context:
space:
mode:
Diffstat (limited to 'rfc.go')
-rw-r--r--rfc.go76
1 files changed, 76 insertions, 0 deletions
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
+}