1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:24:42 -07:00

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 <kev@inburke.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Agniva De Sarker 2018-04-15 00:15:41 +05:30 committed by Brad Fitzpatrick
parent d11f6ec946
commit 8723cc7387
2 changed files with 7 additions and 6 deletions

View File

@ -6,6 +6,7 @@
package blog // import "golang.org/x/tools/blog" package blog // import "golang.org/x/tools/blog"
import ( import (
"bytes"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
@ -153,7 +154,7 @@ func sectioned(d *present.Doc) bool {
// authors returns a comma-separated list of author names. // authors returns a comma-separated list of author names.
func authors(authors []present.Author) string { func authors(authors []present.Author) string {
var b strings.Builder var b bytes.Buffer
last := len(authors) - 1 last := len(authors) - 1
for i, a := range authors { for i, a := range authors {
if i > 0 { if i > 0 {
@ -201,7 +202,7 @@ func (s *Server) loadDocs(root string) error {
if err != nil { if err != nil {
return err return err
} }
var html strings.Builder var html bytes.Buffer
err = d.Render(&html, s.template.doc) err = d.Render(&html, s.template.doc)
if err != nil { if err != nil {
return err return err
@ -369,7 +370,7 @@ func summary(d *Doc) string {
// skip everything but non-text elements // skip everything but non-text elements
continue continue
} }
var buf strings.Builder var buf bytes.Buffer
for _, s := range text.Lines { for _, s := range text.Lines {
buf.WriteString(string(present.Style(s))) buf.WriteString(string(present.Style(s)))
buf.WriteByte('\n') buf.WriteByte('\n')
@ -429,7 +430,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
var err error var err error
if s.cfg.ServeLocalLinks { if s.cfg.ServeLocalLinks {
var buf strings.Builder var buf bytes.Buffer
err = t.ExecuteTemplate(&buf, "root", d) err = t.ExecuteTemplate(&buf, "root", d)
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@ -5,7 +5,7 @@
package blog package blog
import ( import (
"strings" "bytes"
"testing" "testing"
) )
@ -31,7 +31,7 @@ func TestLinkRewrite(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
var buf strings.Builder var buf bytes.Buffer
_, err := golangOrgAbsLinkReplacer.WriteString(&buf, test.input) _, err := golangOrgAbsLinkReplacer.WriteString(&buf, test.input)
if err != nil { if err != nil {
t.Errorf("unexpected error during replacing links. Got: %#v, Want: nil.\n", err) t.Errorf("unexpected error during replacing links. Got: %#v, Want: nil.\n", err)