summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-21 16:29:17 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-21 16:29:17 +0200
commit878316d21afdc89bcc0969c0a614242249abe5fe (patch)
tree8588051bec107a25b58ee5afc944a2105c66742f
parente9850ea5dca5332b70e53bf215ea2084f214c94a (diff)
Add pretty print and id
-rw-r--r--rfc.go30
1 files changed, 29 insertions, 1 deletions
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
+}