From 8723cc7387521a38ae242937c34eb8e15055e484 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sun, 15 Apr 2018 00:15:41 +0530 Subject: [PATCH] blog: revert strings.Builder to bytes.Buffer The blog repo can still be imported by older Go versions. Hence, we need to maintain backward compatibility. Change-Id: I0235d888734c2f191d04924815f8ffea0239aace Reviewed-on: https://go-review.googlesource.com/107175 Run-TryBot: Kevin Burke Reviewed-by: Brad Fitzpatrick --- blog/blog.go | 9 +++++---- blog/blog_test.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/blog/blog.go b/blog/blog.go index 633014d31f..c26b6adbcb 100644 --- a/blog/blog.go +++ b/blog/blog.go @@ -6,6 +6,7 @@ package blog // import "golang.org/x/tools/blog" import ( + "bytes" "encoding/json" "encoding/xml" "fmt" @@ -153,7 +154,7 @@ func sectioned(d *present.Doc) bool { // authors returns a comma-separated list of author names. func authors(authors []present.Author) string { - var b strings.Builder + var b bytes.Buffer last := len(authors) - 1 for i, a := range authors { if i > 0 { @@ -201,7 +202,7 @@ func (s *Server) loadDocs(root string) error { if err != nil { return err } - var html strings.Builder + var html bytes.Buffer err = d.Render(&html, s.template.doc) if err != nil { return err @@ -369,7 +370,7 @@ func summary(d *Doc) string { // skip everything but non-text elements continue } - var buf strings.Builder + var buf bytes.Buffer for _, s := range text.Lines { buf.WriteString(string(present.Style(s))) buf.WriteByte('\n') @@ -429,7 +430,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } var err error if s.cfg.ServeLocalLinks { - var buf strings.Builder + var buf bytes.Buffer err = t.ExecuteTemplate(&buf, "root", d) if err != nil { log.Println(err) diff --git a/blog/blog_test.go b/blog/blog_test.go index 6e9f6411ce..90155feadc 100644 --- a/blog/blog_test.go +++ b/blog/blog_test.go @@ -5,7 +5,7 @@ package blog import ( - "strings" + "bytes" "testing" ) @@ -31,7 +31,7 @@ func TestLinkRewrite(t *testing.T) { }, } for _, test := range tests { - var buf strings.Builder + var buf bytes.Buffer _, err := golangOrgAbsLinkReplacer.WriteString(&buf, test.input) if err != nil { t.Errorf("unexpected error during replacing links. Got: %#v, Want: nil.\n", err)