mirror of
https://github.com/golang/go
synced 2024-11-21 15:24:45 -07:00
doc: only trim newlines in tmpltohtml, gofmt progs
R=golang-dev, r, r CC=golang-dev https://golang.org/cl/5530048
This commit is contained in:
parent
c7e91724c0
commit
468e692e38
@ -119,8 +119,8 @@ Next up, here's a version of the Unix utility <code>echo(1)</code>:
|
||||
-->package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"flag" // command line option parser
|
||||
"os"
|
||||
)
|
||||
|
||||
var omitNewline = flag.Bool("n", false, "don't print final newline")
|
||||
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -27,6 +27,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), 500)
|
||||
}
|
||||
}
|
||||
|
||||
// STOP OMIT
|
||||
|
||||
type ap struct{}
|
||||
|
@ -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{}
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user