From 878316d21afdc89bcc0969c0a614242249abe5fe Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 21 Jul 2015 16:29:17 +0200 Subject: Add pretty print and id --- rfc.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rfc.go b/rfc.go index 8f479e3..61ea9b0 100644 --- a/rfc.go +++ b/rfc.go @@ -3,6 +3,7 @@ package rfc import ( "bytes" "encoding/xml" + "fmt" "io" "io/ioutil" "net/http" @@ -18,7 +19,7 @@ type Index struct { } type Entry struct { - ID string `xml:"doc-id"` + DocID string `xml:"doc-id"` Title string `xml:"title"` Authors []string `xml:"author>name"` Month string `xml:"date>month"` @@ -74,3 +75,30 @@ func Open() (io.Reader, error) { } return bytes.NewReader(body), nil } + +func refs(prefix string, s []string) (ret string) { + if s != nil { + ret = fmt.Sprint(", ", prefix, ": ") + for i, v := range s { + if i != 0 { + ret += ", " + } + ret += fmt.Sprint(v) + } + } + return +} + +func (e Entry) String() string { + ret := fmt.Sprint(e.DocID, " ", e.Title) + ret += fmt.Sprint(refs("Updates", e.Updates)) + ret += fmt.Sprint(refs("Obsoletes", e.Obsoletes)) + ret += fmt.Sprint(refs("Updated by", e.UpdatedBy)) + ret += fmt.Sprint(refs("Obsoleted by", e.ObsoletedBy)) + return ret +} + +func (e Entry) ID() (id int) { + fmt.Sprintf(e.DocID, "RFC%d", &id) + return +} -- cgit v1.2.3