Skip to content

Commit 468e692

Browse files
committed
doc: only trim newlines in tmpltohtml, gofmt progs
R=golang-dev, r, r CC=golang-dev https://golang.org/cl/5530048
1 parent c7e9172 commit 468e692

13 files changed

+43
-29
lines changed

doc/articles/error_handling.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</p>
2121

2222
<pre><!--{{code "progs/error.go" `/func openFile/` `/STOP/`}}
23-
-->f, err := os.Open(&#34;filename.ext&#34;)
23+
--> f, err := os.Open(&#34;filename.ext&#34;)
2424
if err != nil {
2525
log.Fatal(err)
2626
}
@@ -100,7 +100,7 @@
100100
</p>
101101

102102
<pre><!--{{code "progs/error.go" `/func printErr/` `/STOP/`}}
103-
-->f, err := Sqrt(-1)
103+
--> f, err := Sqrt(-1)
104104
if err != nil {
105105
fmt.Println(err)
106106
}</pre>
@@ -125,7 +125,7 @@
125125
</p>
126126

127127
<pre><!--{{code "progs/error.go" `/fmtError/` `/STOP/`}}
128-
-->if f &lt; 0 {
128+
--> if f &lt; 0 {
129129
return 0, fmt.Errorf(&#34;math: square root of negative number %g&#34;, f)
130130
}</pre>
131131

@@ -177,7 +177,7 @@
177177
</p>
178178

179179
<pre><!--{{code "progs/error.go" `/func decodeError/` `/STOP/`}}
180-
-->if err := dec.Decode(&amp;val); err != nil {
180+
--> if err := dec.Decode(&amp;val); err != nil {
181181
if serr, ok := err.(*json.SyntaxError); ok {
182182
line, col := findLine(f, serr.Offset)
183183
return fmt.Errorf(&#34;%s:%d:%d: %v&#34;, f.Name(), line, col, err)
@@ -216,7 +216,7 @@
216216
</p>
217217

218218
<pre><!--{{code "progs/error.go" `/func netError/` `/STOP/`}}
219-
-->if nerr, ok := err.(net.Error); ok &amp;&amp; nerr.Temporary() {
219+
--> if nerr, ok := err.(net.Error); ok &amp;&amp; nerr.Temporary() {
220220
time.Sleep(1e9)
221221
continue
222222
}

doc/go1.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h3 id="append">Append</h3>
4444
</p>
4545

4646
<pre><!--{{code "progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
47-
-->greeting := []byte{}
47+
--> greeting := []byte{}
4848
greeting = append(greeting, []byte(&#34;hello &#34;)...)</pre>
4949

5050
<p>
@@ -54,7 +54,7 @@ <h3 id="append">Append</h3>
5454
</p>
5555

5656
<pre><!--{{code "progs/go1.go" `/append.*world/`}}
57-
-->greeting = append(greeting, &#34;world&#34;...)</pre>
57+
--> greeting = append(greeting, &#34;world&#34;...)</pre>
5858

5959
<p>
6060
<em>Updating</em>:
@@ -95,7 +95,7 @@ <h3 id="literals">Composite literals</h3>
9595
</p>
9696

9797
<pre><!--{{code "progs/go1.go" `/type Date struct/` `/STOP/`}}
98-
-->type Date struct {
98+
--> type Date struct {
9999
month string
100100
day int
101101
}
@@ -182,7 +182,7 @@ <h3 id="rune">The rune type</h3>
182182
</p>
183183

184184
<pre><!--{{code "progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
185-
-->delta := &#39;δ&#39; // delta has type rune.
185+
--> delta := &#39;δ&#39; // delta has type rune.
186186
var DELTA rune
187187
DELTA = unicode.ToUpper(delta)
188188
epsilon := unicode.ToLower(DELTA + 1)
@@ -231,7 +231,7 @@ <h3 id="delete">Deleting from maps</h3>
231231
</p>
232232

233233
<pre><!--{{code "progs/go1.go" `/delete\(m, k\)/`}}
234-
-->delete(m, k)</pre>
234+
--> delete(m, k)</pre>
235235

236236
<p>
237237
will delete the map entry retrieved by the expression <code>m[k]</code>.
@@ -258,7 +258,7 @@ <h3 id="iteration">Iterating in maps</h3>
258258
</p>
259259

260260
<pre><!--{{code "progs/go1.go" `/Sunday/` `/^ }/`}}
261-
-->m := map[string]int{&#34;Sunday&#34;: 0, &#34;Monday&#34;: 1}
261+
--> m := map[string]int{&#34;Sunday&#34;: 0, &#34;Monday&#34;: 1}
262262
for name, value := range m {
263263
// This loop should not assume Sunday will be visited first.
264264
f(name, value)
@@ -292,7 +292,7 @@ <h3 id="multiple_assignment">Multiple assignment</h3>
292292
</p>
293293

294294
<pre><!--{{code "progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
295-
-->sa := []int{1, 2, 3}
295+
--> sa := []int{1, 2, 3}
296296
i := 0
297297
i, sa[i] = 1, 2 // sets i = 1, sa[0] = 2
298298

@@ -409,7 +409,7 @@ <h3 id="equality">Equality of structs and arrays</h3>
409409
</p>
410410

411411
<pre><!--{{code "progs/go1.go" `/type Day struct/` `/Printf/`}}
412-
-->type Day struct {
412+
--> type Day struct {
413413
long string
414414
short string
415415
}
@@ -585,7 +585,7 @@ <h3 id="errors">The error type and errors package</h3>
585585
</p>
586586

587587
<pre><!--{{code "progs/go1.go" `/ErrSyntax/`}}
588-
-->var ErrSyntax = errors.New(&#34;syntax error&#34;)</pre>
588+
--> var ErrSyntax = errors.New(&#34;syntax error&#34;)</pre>
589589

590590
<p>
591591
<em>Updating</em>:

doc/go_tutorial.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ <h2>Echo</h2>
119119
-->package main
120120

121121
import (
122-
&#34;os&#34;
123122
&#34;flag&#34; // command line option parser
123+
&#34;os&#34;
124124
)
125125

126126
var omitNewline = flag.Bool(&#34;n&#34;, false, &#34;don&#39;t print final newline&#34;)
@@ -209,7 +209,7 @@ <h2>Echo</h2>
209209
There's one in the <code>for</code> clause on the next line:
210210
<p>
211211
<pre><!--{{code "progs/echo.go" `/for/`}}
212-
-->for i := 0; i &lt; flag.NArg(); i++ {</pre>
212+
--> for i := 0; i &lt; flag.NArg(); i++ {</pre>
213213
<p>
214214
The <code>flag</code> package has parsed the arguments and left the non-flag arguments
215215
in a list that can be iterated over in the obvious way.
@@ -258,7 +258,7 @@ <h2>An Interlude about Types</h2>
258258
reassigning it. This snippet from <code>strings.go</code> is legal code:
259259
<p>
260260
<pre><!--{{code "progs/strings.go" `/hello/` `/ciao/`}}
261-
-->s := &#34;hello&#34;
261+
--> s := &#34;hello&#34;
262262
if s[1] != &#39;e&#39; {
263263
os.Exit(1)
264264
}
@@ -811,8 +811,7 @@ <h2>Rotting cats</h2>
811811

812812
func (r13 *rotate13) String() string {
813813
return r13.source.String()
814-
}
815-
// end of rotate13 implementation</pre>
814+
}</pre>
816815
<p>
817816
(The <code>rot13</code> function called in <code>Read</code> is trivial and not worth reproducing here.)
818817
<p>
@@ -990,7 +989,7 @@ <h2>Printing</h2>
990989
integer and can do the right thing for you. The snippet
991990
<p>
992991
<pre><!--{{code "progs/print.go" 10 11}}
993-
-->var u64 uint64 = 1&lt;&lt;64 - 1
992+
--> var u64 uint64 = 1&lt;&lt;64 - 1
994993
fmt.Printf(&#34;%d %d\n&#34;, u64, int64(u64))</pre>
995994
<p>
996995
prints
@@ -1003,7 +1002,7 @@ <h2>Printing</h2>
10031002
appropriate style, any value, even an array or structure. The output of
10041003
<p>
10051004
<pre><!--{{code "progs/print.go" 14 20}}
1006-
-->type T struct {
1005+
--> type T struct {
10071006
a int
10081007
b string
10091008
}
@@ -1025,7 +1024,7 @@ <h2>Printing</h2>
10251024
to that of the <code>Printf</code> call above.
10261025
<p>
10271026
<pre><!--{{code "progs/print.go" 21 22}}
1028-
-->fmt.Print(u64, &#34; &#34;, t, &#34; &#34;, a, &#34;\n&#34;)
1027+
--> fmt.Print(u64, &#34; &#34;, t, &#34; &#34;, a, &#34;\n&#34;)
10291028
fmt.Println(u64, t, a)</pre>
10301029
<p>
10311030
If you have your own type you'd like <code>Printf</code> or <code>Print</code> to format,
@@ -1442,10 +1441,10 @@ <h2>Multiplexing</h2>
14421441
at the end of main:
14431442
<p>
14441443
<pre><!--{{code "progs/server1.go" `/adder,.quit/`}}
1445-
-->adder, quit := startServer(func(a, b int) int { return a + b })</pre>
1444+
--> adder, quit := startServer(func(a, b int) int { return a + b })</pre>
14461445
...
14471446
<pre><!--{{code "progs/server1.go" `/quit....true/`}}
1448-
-->quit &lt;- true</pre>
1447+
--> quit &lt;- true</pre>
14491448
<p>
14501449
There's a lot more to Go programming and concurrent programming in general but this
14511450
quick tour should give you some of the basics.

doc/progs/cat_rot13.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func (r13 *rotate13) Read(b []byte) (ret int, err error) {
4747
func (r13 *rotate13) String() string {
4848
return r13.source.String()
4949
}
50-
// end of rotate13 implementation
50+
51+
// end of rotate13 implementation OMIT
5152

5253
func cat(r reader) {
5354
const NBUF = 512

doc/progs/defer2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func g(i int) {
3535
fmt.Println("Printing in g", i)
3636
g(i + 1)
3737
}
38+
3839
// STOP OMIT
3940

4041
// Revised version.
@@ -53,4 +54,5 @@ func CopyFile(dstName, srcName string) (written int64, err error) {
5354

5455
return io.Copy(dst, src)
5556
}
57+
5658
// STOP OMIT

doc/progs/echo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package main
66

77
import (
8-
"os"
98
"flag" // command line option parser
9+
"os"
1010
)
1111

1212
var omitNewline = flag.Bool("n", false, "don't print final newline")

doc/progs/error.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ type errorString struct {
3838
func (e *errorString) Error() string {
3939
return e.s
4040
}
41+
4142
// STOP OMIT
4243

4344
// New returns an error that formats as the given text.
4445
func New(text string) error {
4546
return &errorString{text}
4647
}
48+
4749
// STOP OMIT
4850

4951
func Sqrt(f float64) (float64, error) {
@@ -53,6 +55,7 @@ func Sqrt(f float64) (float64, error) {
5355
// implementation
5456
return 0, nil // OMIT
5557
}
58+
5659
// STOP OMIT
5760

5861
func printErr() (int, error) { // OMIT
@@ -74,6 +77,7 @@ type NegativeSqrtError float64
7477
func (f NegativeSqrtError) Error() string {
7578
return fmt.Sprintf("math: square root of negative number %g", float64(f))
7679
}
80+
7781
// STOP OMIT
7882

7983
type SyntaxError struct {
@@ -82,6 +86,7 @@ type SyntaxError struct {
8286
}
8387

8488
func (e *SyntaxError) Error() string { return e.msg }
89+
8590
// STOP OMIT
8691

8792
func decodeError(dec *json.Decoder, val struct{}) error { // OMIT

doc/progs/error2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) {
2727
http.Error(w, err.Error(), 500)
2828
}
2929
}
30+
3031
// STOP OMIT
3132

3233
type ap struct{}

doc/progs/error3.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func init() {
1515
http.Handle("/view", appHandler(viewRecord))
1616
}
17+
1718
// STOP OMIT
1819

1920
func viewRecord(w http.ResponseWriter, r *http.Request) error {
@@ -25,6 +26,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) error {
2526
}
2627
return viewTemplate.Execute(w, record)
2728
}
29+
2830
// STOP OMIT
2931

3032
type appHandler func(http.ResponseWriter, *http.Request) error
@@ -34,6 +36,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
3436
http.Error(w, err.Error(), 500)
3537
}
3638
}
39+
3740
// STOP OMIT
3841

3942
type ap struct{}

doc/progs/error4.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type appError struct {
1616
Message string
1717
Code int
1818
}
19+
1920
// STOP OMIT
2021

2122
type appHandler func(http.ResponseWriter, *http.Request) *appError
@@ -27,6 +28,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2728
http.Error(w, e.Message, e.Code)
2829
}
2930
}
31+
3032
// STOP OMIT
3133

3234
func viewRecord(w http.ResponseWriter, r *http.Request) *appError {
@@ -41,6 +43,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) *appError {
4143
}
4244
return nil
4345
}
46+
4447
// STOP OMIT
4548

4649
func init() {

doc/progs/go1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ type SyntaxError struct {
147147
func (se *SyntaxError) Error() string {
148148
return fmt.Sprintf("%s:%d: %s", se.File, se.Line, se.Message)
149149
}
150+
150151
// END ERROR EXAMPLE OMIT
151152

152153
func errorExample() {

doc/progs/sortmain.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package main
66

77
import (
8-
"fmt"
98
"./sort"
9+
"fmt"
1010
)
1111

1212
func ints() {
@@ -61,7 +61,6 @@ func days() {
6161
fmt.Printf("\n")
6262
}
6363

64-
6564
func main() {
6665
ints()
6766
strings()

doc/tmpltohtml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func code(file string, arg ...interface{}) (string, error) {
114114
return "", fmt.Errorf("incorrect code invocation: code %q %q", file, arg)
115115
}
116116
// Trim spaces from output.
117-
text = strings.TrimSpace(text)
117+
text = strings.Trim(text, "\n")
118118
// Replace tabs by spaces, which work better in HTML.
119119
text = strings.Replace(text, "\t", " ", -1)
120120
// Escape the program text for HTML.

0 commit comments

Comments
 (0)