summaryrefslogtreecommitdiff
path: root/rfc.go
blob: f608d0cf68c5b485d69f5320617da223f1f893ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
}