]> Cypherpunks repositories - gostls13.git/commitdiff
doc: only trim newlines in tmpltohtml, gofmt progs
authorAndrew Gerrand <adg@golang.org>
Mon, 9 Jan 2012 09:05:34 +0000 (20:05 +1100)
committerAndrew Gerrand <adg@golang.org>
Mon, 9 Jan 2012 09:05:34 +0000 (20:05 +1100)
R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5530048

13 files changed:
doc/articles/error_handling.html
doc/go1.html
doc/go_tutorial.html
doc/progs/cat_rot13.go
doc/progs/defer2.go
doc/progs/echo.go
doc/progs/error.go
doc/progs/error2.go
doc/progs/error3.go
doc/progs/error4.go
doc/progs/go1.go
doc/progs/sortmain.go
doc/tmpltohtml.go

index 48292c2c99fa2cf3d94eeb52b0530bb6de94baeb..89f29983d1b6d7a3c24792204ac8987b5fbcae84 100644 (file)
@@ -20,7 +20,7 @@ occurs it calls <code>log.Fatal</code> to print the error message and stop.
 </p>
 
 <pre><!--{{code "progs/error.go" `/func openFile/` `/STOP/`}}
--->f, err := os.Open(&#34;filename.ext&#34;)
+-->    f, err := os.Open(&#34;filename.ext&#34;)
     if err != nil {
         log.Fatal(err)
     }
@@ -100,7 +100,7 @@ A caller passing a negative argument to <code>Sqrt</code> receives a non-nil
 </p>
 
 <pre><!--{{code "progs/error.go" `/func printErr/` `/STOP/`}}
--->f, err := Sqrt(-1)
+-->    f, err := Sqrt(-1)
     if err != nil {
         fmt.Println(err)
     }</pre>
@@ -125,7 +125,7 @@ rules and returns it as an <code>error</code> created by
 </p>
 
 <pre><!--{{code "progs/error.go" `/fmtError/` `/STOP/`}}
--->if f &lt; 0 {
+-->    if f &lt; 0 {
         return 0, fmt.Errorf(&#34;math: square root of negative number %g&#34;, f)
     }</pre>
 
@@ -177,7 +177,7 @@ messages:
 </p>
 
 <pre><!--{{code "progs/error.go" `/func decodeError/` `/STOP/`}}
--->if err := dec.Decode(&amp;val); err != nil {
+-->    if err := dec.Decode(&amp;val); err != nil {
         if serr, ok := err.(*json.SyntaxError); ok {
             line, col := findLine(f, serr.Offset)
             return fmt.Errorf(&#34;%s:%d:%d: %v&#34;, f.Name(), line, col, err)
@@ -216,7 +216,7 @@ up otherwise.
 </p>
 
 <pre><!--{{code "progs/error.go" `/func netError/` `/STOP/`}}
--->if nerr, ok := err.(net.Error); ok &amp;&amp; nerr.Temporary() {
+-->        if nerr, ok := err.(net.Error); ok &amp;&amp; nerr.Temporary() {
             time.Sleep(1e9)
             continue
         }
index dbf263e08217d82393783ef23674af93ba95a414..77820d0807bd2b805d1ca1d829b06d1e36c6077f 100644 (file)
@@ -44,7 +44,7 @@ call.
 </p>
 
 <pre><!--{{code "progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
--->greeting := []byte{}
+-->    greeting := []byte{}
     greeting = append(greeting, []byte(&#34;hello &#34;)...)</pre>
 
 <p>
@@ -54,7 +54,7 @@ slice; the conversion is no longer necessary:
 </p>
 
 <pre><!--{{code "progs/go1.go" `/append.*world/`}}
--->greeting = append(greeting, &#34;world&#34;...)</pre>
+-->    greeting = append(greeting, &#34;world&#34;...)</pre>
 
 <p>
 <em>Updating</em>:
@@ -95,7 +95,7 @@ All four of the initializations in this example are legal; the last one was ille
 </p>
 
 <pre><!--{{code "progs/go1.go" `/type Date struct/` `/STOP/`}}
--->type Date struct {
+-->    type Date struct {
         month string
         day   int
     }
@@ -182,7 +182,7 @@ relatives now take and return a <code>rune</code>.
 </p>
 
 <pre><!--{{code "progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
--->delta := &#39;δ&#39; // delta has type rune.
+-->    delta := &#39;δ&#39; // delta has type rune.
     var DELTA rune
     DELTA = unicode.ToUpper(delta)
     epsilon := unicode.ToLower(DELTA + 1)
@@ -231,7 +231,7 @@ function, <code>delete</code>.  The call
 </p>
 
 <pre><!--{{code "progs/go1.go" `/delete\(m, k\)/`}}
--->delete(m, k)</pre>
+-->    delete(m, k)</pre>
 
 <p>
 will delete the map entry retrieved by the expression <code>m[k]</code>.
@@ -258,7 +258,7 @@ Code should not assume that the elements are visited in any particular order.
 </p>
 
 <pre><!--{{code "progs/go1.go" `/Sunday/` `/^  }/`}}
--->m := map[string]int{&#34;Sunday&#34;: 0, &#34;Monday&#34;: 1}
+-->    m := map[string]int{&#34;Sunday&#34;: 0, &#34;Monday&#34;: 1}
     for name, value := range m {
         // This loop should not assume Sunday will be visited first.
         f(name, value)
@@ -292,7 +292,7 @@ These examples illustrate the behavior.
 </p>
 
 <pre><!--{{code "progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
--->sa := []int{1, 2, 3}
+-->    sa := []int{1, 2, 3}
     i := 0
     i, sa[i] = 1, 2 // sets i = 1, sa[0] = 2
 
@@ -409,7 +409,7 @@ As a result, structs and arrays can now be used as map keys:
 </p>
 
 <pre><!--{{code "progs/go1.go" `/type Day struct/` `/Printf/`}}
--->type Day struct {
+-->    type Day struct {
         long  string
         short string
     }
@@ -585,7 +585,7 @@ to turn a string into an error. It replaces the old <code>os.NewError</code>.
 </p>
 
 <pre><!--{{code "progs/go1.go" `/ErrSyntax/`}}
--->var ErrSyntax = errors.New(&#34;syntax error&#34;)</pre>
+-->    var ErrSyntax = errors.New(&#34;syntax error&#34;)</pre>
                
 <p>
 <em>Updating</em>:
index 13c352b87cdebb359958a2163d60c1fe75beb5b1..071ca1aa9d7272f2144af884caf3b6e8fe1d5fad 100644 (file)
@@ -119,8 +119,8 @@ Next up, here's a version of the Unix utility <code>echo(1)</code>:
 -->package main
 
 import (
-    &#34;os&#34;
     &#34;flag&#34; // command line option parser
+    &#34;os&#34;
 )
 
 var omitNewline = flag.Bool(&#34;n&#34;, false, &#34;don&#39;t print final newline&#34;)
@@ -209,7 +209,7 @@ The <code>:=</code> operator is used a lot in Go to represent an initializing de
 There's one in the <code>for</code> clause on the next line:
 <p>
 <pre><!--{{code "progs/echo.go" `/for/`}}
--->for i := 0; i &lt; flag.NArg(); i++ {</pre>
+-->    for i := 0; i &lt; flag.NArg(); i++ {</pre>
 <p>
 The <code>flag</code> package has parsed the arguments and left the non-flag arguments
 in a list that can be iterated over in the obvious way.
@@ -258,7 +258,7 @@ of course you can change a string <i>variable</i> simply by
 reassigning it.  This snippet from <code>strings.go</code> is legal code:
 <p>
 <pre><!--{{code "progs/strings.go" `/hello/` `/ciao/`}}
--->s := &#34;hello&#34;
+-->    s := &#34;hello&#34;
     if s[1] != &#39;e&#39; {
         os.Exit(1)
     }
@@ -811,8 +811,7 @@ func (r13 *rotate13) Read(b []byte) (ret int, err error) {
 
 func (r13 *rotate13) String() string {
     return r13.source.String()
-}
-// end of rotate13 implementation</pre>
+}</pre>
 <p>
 (The <code>rot13</code> function called in <code>Read</code> is trivial and not worth reproducing here.)
 <p>
@@ -990,7 +989,7 @@ can just say <code>%d</code>; <code>Printf</code> knows the size and signedness
 integer and can do the right thing for you.  The snippet
 <p>
 <pre><!--{{code "progs/print.go" 10 11}}
--->var u64 uint64 = 1&lt;&lt;64 - 1
+-->    var u64 uint64 = 1&lt;&lt;64 - 1
     fmt.Printf(&#34;%d %d\n&#34;, u64, int64(u64))</pre>
 <p>
 prints
@@ -1003,7 +1002,7 @@ In fact, if you're lazy the format <code>%v</code> will print, in a simple
 appropriate style, any value, even an array or structure.  The output of
 <p>
 <pre><!--{{code "progs/print.go" 14 20}}
--->type T struct {
+-->    type T struct {
         a int
         b string
     }
@@ -1025,7 +1024,7 @@ and adds a newline.  The output of each of these two lines is identical
 to that of the <code>Printf</code> call above.
 <p>
 <pre><!--{{code "progs/print.go" 21 22}}
--->fmt.Print(u64, &#34; &#34;, t, &#34; &#34;, a, &#34;\n&#34;)
+-->    fmt.Print(u64, &#34; &#34;, t, &#34; &#34;, a, &#34;\n&#34;)
     fmt.Println(u64, t, a)</pre>
 <p>
 If you have your own type you'd like <code>Printf</code> or <code>Print</code> to format,
@@ -1442,10 +1441,10 @@ All that's left is to strobe the <code>quit</code> channel
 at the end of main:
 <p>
 <pre><!--{{code "progs/server1.go" `/adder,.quit/`}}
--->adder, quit := startServer(func(a, b int) int { return a + b })</pre>
+-->    adder, quit := startServer(func(a, b int) int { return a + b })</pre>
 ...
 <pre><!--{{code "progs/server1.go" `/quit....true/`}}
--->quit &lt;- true</pre>
+-->    quit &lt;- true</pre>
 <p>
 There's a lot more to Go programming and concurrent programming in general but this
 quick tour should give you some of the basics.
index ec2521ce50010f9008b179ba846a9b36f86f5d38..c8584ed47cf56613824839404177fad052c63ffb 100644 (file)
@@ -47,7 +47,8 @@ func (r13 *rotate13) Read(b []byte) (ret int, err error) {
 func (r13 *rotate13) String() string {
        return r13.source.String()
 }
-// end of rotate13 implementation
+
+// end of rotate13 implementation OMIT
 
 func cat(r reader) {
        const NBUF = 512
index be6791d5c7bcb5368efdd8588fa1b9aadc22732c..341a1410f3a22e6124ec705c4c8bff8d9efe61ac 100644 (file)
@@ -35,6 +35,7 @@ func g(i int) {
        fmt.Println("Printing in g", i)
        g(i + 1)
 }
+
 // STOP OMIT
 
 // Revised version.
@@ -53,4 +54,5 @@ func CopyFile(dstName, srcName string) (written int64, err error) {
 
        return io.Copy(dst, src)
 }
+
 // STOP OMIT
index 3260edd747a00a04254816d728f927f842e81f1b..432e808207598cd3a669e9bd75880a1e890dec8e 100644 (file)
@@ -5,8 +5,8 @@
 package main
 
 import (
-       "os"
        "flag" // command line option parser
+       "os"
 )
 
 var omitNewline = flag.Bool("n", false, "don't print final newline")
index 3f98709f7ce5834c4b36b9beea4228a21cb5f23a..ffa7ec1ccaef7784407ac6ebaf92e5d41c3cd9fc 100644 (file)
@@ -38,12 +38,14 @@ type errorString struct {
 func (e *errorString) Error() string {
        return e.s
 }
+
 // STOP OMIT
 
 // New returns an error that formats as the given text.
 func New(text string) error {
        return &errorString{text}
 }
+
 // STOP OMIT
 
 func Sqrt(f float64) (float64, error) {
@@ -53,6 +55,7 @@ func Sqrt(f float64) (float64, error) {
        // implementation
        return 0, nil // OMIT
 }
+
 // STOP OMIT
 
 func printErr() (int, error) { // OMIT
@@ -74,6 +77,7 @@ type NegativeSqrtError float64
 func (f NegativeSqrtError) Error() string {
        return fmt.Sprintf("math: square root of negative number %g", float64(f))
 }
+
 // STOP OMIT
 
 type SyntaxError struct {
@@ -82,6 +86,7 @@ type SyntaxError struct {
 }
 
 func (e *SyntaxError) Error() string { return e.msg }
+
 // STOP OMIT
 
 func decodeError(dec *json.Decoder, val struct{}) error { // OMIT
index fe72350181edbd04fb17fd3d98fa8bac8446bb14..2b0e0c3563a56d4738ec6deadcb850e2490624a1 100644 (file)
@@ -27,6 +27,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) {
                http.Error(w, err.Error(), 500)
        }
 }
+
 // STOP OMIT
 
 type ap struct{}
index 8305edc42019a5bd0916a572953e942c2ff22eee..e4e57e077b52ace4126868985272fe060e5d9b5d 100644 (file)
@@ -14,6 +14,7 @@ import (
 func init() {
        http.Handle("/view", appHandler(viewRecord))
 }
+
 // STOP OMIT
 
 func viewRecord(w http.ResponseWriter, r *http.Request) error {
@@ -25,6 +26,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) error {
        }
        return viewTemplate.Execute(w, record)
 }
+
 // STOP OMIT
 
 type appHandler func(http.ResponseWriter, *http.Request) error
@@ -34,6 +36,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
                http.Error(w, err.Error(), 500)
        }
 }
+
 // STOP OMIT
 
 type ap struct{}
index 661dcdc2b6983db4514f43043d0fae0aa22ef823..8f35cf74bb852e96ec7aac431337ac5aed5f862f 100644 (file)
@@ -16,6 +16,7 @@ type appError struct {
        Message string
        Code    int
 }
+
 // STOP OMIT
 
 type appHandler func(http.ResponseWriter, *http.Request) *appError
@@ -27,6 +28,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
                http.Error(w, e.Message, e.Code)
        }
 }
+
 // STOP OMIT
 
 func viewRecord(w http.ResponseWriter, r *http.Request) *appError {
@@ -41,6 +43,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) *appError {
        }
        return nil
 }
+
 // STOP OMIT
 
 func init() {
index b1bcc43f615eb3bd917dd32b0cb1cd3708f6f637..0eccca321b991d7a177f117a56a8405ce78c791b 100644 (file)
@@ -147,6 +147,7 @@ type SyntaxError struct {
 func (se *SyntaxError) Error() string {
        return fmt.Sprintf("%s:%d: %s", se.File, se.Line, se.Message)
 }
+
 // END ERROR EXAMPLE OMIT
 
 func errorExample() {
index c1babb01f81f0d3f5cc63c609087d1072fd3c7b4..1bc3355fd06bd5ac2d3d318a271fadc5ae789236 100644 (file)
@@ -5,8 +5,8 @@
 package main
 
 import (
-       "fmt"
        "./sort"
+       "fmt"
 )
 
 func ints() {
@@ -61,7 +61,6 @@ func days() {
        fmt.Printf("\n")
 }
 
-
 func main() {
        ints()
        strings()
index dbd27ab685ba546c81a9fb8ede85ddbf2a51ec7d..70745f4ddddf77e5ec1f7d3690caae8fa960e57b 100644 (file)
@@ -114,7 +114,7 @@ func code(file string, arg ...interface{}) (string, error) {
                return "", fmt.Errorf("incorrect code invocation: code %q %q", file, arg)
        }
        // Trim spaces from output.
-       text = strings.TrimSpace(text)
+       text = strings.Trim(text, "\n")
        // Replace tabs by spaces, which work better in HTML.
        text = strings.Replace(text, "\t", "    ", -1)
        // Escape the program text for HTML.