Skip to content

Commit 3560419

Browse files
kostya-shadg
authored andcommitted
godoc/static: makestatic.go: gofmt generated code
Change-Id: Ibe0948fa283af94b1213e9ef344ef9eda6e59c05 Reviewed-on: https://go-review.googlesource.com/23532 Reviewed-by: Andrew Gerrand <[email protected]>
1 parent ba484b0 commit 3560419

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

godoc/static/makestatic.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
package main
1111

1212
import (
13-
"bufio"
1413
"bytes"
1514
"fmt"
15+
"go/format"
1616
"io/ioutil"
1717
"os"
1818
"unicode/utf8"
@@ -83,27 +83,28 @@ func makestatic() error {
8383
return err
8484
}
8585
defer f.Close()
86-
w := bufio.NewWriter(f)
87-
fmt.Fprintf(w, "%v\npackage static\n\n", warning)
88-
fmt.Fprintf(w, "var Files = map[string]string{\n")
86+
buf := new(bytes.Buffer)
87+
fmt.Fprintf(buf, "%v\npackage static\n\n", warning)
88+
fmt.Fprintf(buf, "var Files = map[string]string{\n")
8989
for _, fn := range files {
9090
b, err := ioutil.ReadFile(fn)
9191
if err != nil {
9292
return err
9393
}
94-
fmt.Fprintf(w, "\t%q: ", fn)
94+
fmt.Fprintf(buf, "\t%q: ", fn)
9595
if utf8.Valid(b) {
96-
fmt.Fprintf(w, "`%s`", sanitize(b))
96+
fmt.Fprintf(buf, "`%s`", sanitize(b))
9797
} else {
98-
fmt.Fprintf(w, "%q", b)
98+
fmt.Fprintf(buf, "%q", b)
9999
}
100-
fmt.Fprintln(w, ",\n")
100+
fmt.Fprintln(buf, ",\n")
101101
}
102-
fmt.Fprintln(w, "}")
103-
if err := w.Flush(); err != nil {
102+
fmt.Fprintln(buf, "}")
103+
fmtbuf, err := format.Source(buf.Bytes())
104+
if err != nil {
104105
return err
105106
}
106-
return f.Close()
107+
return ioutil.WriteFile("static.go", fmtbuf, 0666)
107108
}
108109

109110
// sanitize prepares a valid UTF-8 string as a raw string constant.

0 commit comments

Comments
 (0)