From c072558b90f1bbedc2022b0f30c8b1ac4712538e Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Fri, 18 Feb 2011 09:50:58 +0100 Subject: Imported Upstream version 2011.02.15 --- doc/code.html | 6 +- doc/codelab/wiki/final.go | 2 +- doc/codelab/wiki/index.html | 19 +++- doc/codelab/wiki/srcextract.go | 21 ++-- doc/codelab/wiki/wiki.html | 8 +- doc/devel/release.html | 106 +++++++++++++++++++++ doc/effective_go.html | 23 +++-- doc/go_spec.html | 211 +++++++++++++---------------------------- doc/go_tutorial.html | 19 ++-- doc/go_tutorial.txt | 9 +- doc/htmlgen.go | 24 +---- doc/install.html | 18 +++- 12 files changed, 258 insertions(+), 208 deletions(-) (limited to 'doc') diff --git a/doc/code.html b/doc/code.html index 55afe09af..9236cf263 100644 --- a/doc/code.html +++ b/doc/code.html @@ -160,9 +160,9 @@ is the package's default name for imports. Go's convention is that the package name is the last element of the import path: the package imported as "crypto/rot13" should be named rot13. -At the moment, the Go tools impose a restriction that package names are unique -across all packages linked into a single binary, but that restriction -will be lifted soon. +There is no requirement that package names be unique +across all packages linked into a single binary, +only that the import paths (their full file names) be unique.

diff --git a/doc/codelab/wiki/final.go b/doc/codelab/wiki/final.go index 8ecd97d74..c97a699d4 100644 --- a/doc/codelab/wiki/final.go +++ b/doc/codelab/wiki/final.go @@ -64,7 +64,7 @@ func init() { } func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) { - err := templates[tmpl].Execute(p, w) + err := templates[tmpl].Execute(w, p) if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) } diff --git a/doc/codelab/wiki/index.html b/doc/codelab/wiki/index.html index fe99c32d1..fc8c27bfa 100644 --- a/doc/codelab/wiki/index.html +++ b/doc/codelab/wiki/index.html @@ -573,7 +573,11 @@ redirect the client to the edit Page so the content may be created:

-func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
+func viewHandler(w http.ResponseWriter, r *http.Request) {
+	title, err := getTitle(w, r)
+	if err != nil {
+		return
+	}
 	p, err := loadPage(title)
 	if err != nil {
 		http.Redirect(w, r, "/edit/"+title, http.StatusFound)
@@ -658,10 +662,14 @@ Now let's fix up saveHandler:
 

-func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
+func saveHandler(w http.ResponseWriter, r *http.Request) {
+	title, err := getTitle(w, r)
+	if err != nil {
+		return
+	}
 	body := r.FormValue("body")
 	p := &Page{Title: title, Body: []byte(body)}
-	err := p.save()
+	err = p.save()
 	if err != nil {
 		http.Error(w, err.String(), http.StatusInternalServerError)
 		return
@@ -702,7 +710,7 @@ Then we create an init function, which will be called before
 ParseFile that does not return an error code; instead, it panics
 if an error is encountered. A panic is appropriate here; if the templates can't
 be loaded the only sensible thing to do is exit the program.
-

 func init() {
@@ -726,7 +734,7 @@ the Execute method on the appropriate Template from
 
 
 func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
-	err := templates[tmpl].Execute(p, w)
+	err := templates[tmpl].Execute(w, p)
 	if err != nil {
 		http.Error(w, err.String(), http.StatusInternalServerError)
 	}
@@ -747,6 +755,7 @@ Then we can create a global variable to store our validation regexp:
 

+var titleValidator = regexp.MustCompile("^[a-zA-Z0-9]+$")
 

diff --git a/doc/codelab/wiki/srcextract.go b/doc/codelab/wiki/srcextract.go index cab092f58..67294784e 100644 --- a/doc/codelab/wiki/srcextract.go +++ b/doc/codelab/wiki/srcextract.go @@ -9,6 +9,7 @@ import ( "go/token" "log" "os" + "template" ) var ( @@ -31,15 +32,6 @@ func main() { if err != nil { log.Fatal(err) } - // create printer - p := &printer.Config{ - Mode: 0, - Tabwidth: 8, - Styler: nil, - } - if *html { - p.Mode = printer.GenHTML - } // create filter filter := func(name string) bool { return name == *getName @@ -48,8 +40,9 @@ func main() { if !ast.FilterFile(file, filter) { os.Exit(1) } - b := new(bytes.Buffer) - p.Fprint(b, fs, file) + // print the AST + var b bytes.Buffer + printer.Fprint(&b, fs, file) // drop package declaration if !*showPkg { for { @@ -71,5 +64,9 @@ func main() { } } // output - b.WriteTo(os.Stdout) + if *html { + template.HTMLEscape(os.Stdout, b.Bytes()) + } else { + b.WriteTo(os.Stdout) + } } diff --git a/doc/codelab/wiki/wiki.html b/doc/codelab/wiki/wiki.html index ff2c3088b..7ef97b45b 100644 --- a/doc/codelab/wiki/wiki.html +++ b/doc/codelab/wiki/wiki.html @@ -477,7 +477,7 @@ redirect the client to the edit Page so the content may be created:

-!./srcextract.bin -src=final.go -name=viewHandler
+!./srcextract.bin -src=final-noclosure.go -name=viewHandler
 

@@ -539,7 +539,7 @@ Now let's fix up saveHandler:

-!./srcextract.bin -src=final.go -name=saveHandler
+!./srcextract.bin -src=final-noclosure.go -name=saveHandler
 

@@ -574,7 +574,7 @@ Then we create an init function, which will be called before ParseFile that does not return an error code; instead, it panics if an error is encountered. A panic is appropriate here; if the templates can't be loaded the only sensible thing to do is exit the program. -

 !./srcextract.bin -src=final.go -name=init
@@ -610,7 +610,7 @@ Then we can create a global variable to store our validation regexp:
 

-!./srcextract.bin -src=final-noclosure.go -name=TitleValidator
+!./srcextract.bin -src=final-noclosure.go -name=titleValidator
 

diff --git a/doc/devel/release.html b/doc/devel/release.html index f965b5cad..57da6ca60 100644 --- a/doc/devel/release.html +++ b/doc/devel/release.html @@ -5,6 +5,112 @@

This page summarizes the changes between tagged releases of Go. For full details, see the Mercurial change log.

+

2011-02-15

+ +
+This release includes changes to the io and template packages.
+You may need to update your code.
+
+The io.ReadByter and io.ReadRuner interface types have been renamed to
+io.ByteReader and io.RuneReader respectively.
+
+The order of arguments to template.Execute has been reversed to be consistent
+the notion of "destination first", as with io.Copy, fmt.Fprint, and others.
+
+Gotest now works for package main in directories using Make.cmd-based makefiles.
+
+The memory allocation runtime problems from the last release are not completely
+fixed.  The virtual memory exhaustion problems encountered by people using
+ulimit -v have been fixed, but there remain known garbage collector problems
+when using GOMAXPROCS > 1.
+
+Other changes:
+* 5l: stopped generating 64-bit eor.
+* 8l: more work on plan9 support (thanks Yuval Pavel Zholkover).
+* archive/zip: handle files with data descriptors.
+* arm: working peep-hole optimizer.
+* asn1: marshal true as 255, not 1.
+* buffer.go: minor optimization, expanded comment.
+* build: drop syslog on DISABLE_NET_TESTS=1 (thanks Gustavo Niemeyer),
+       allow clean.bash to work on fresh checkout,
+       change "all tests pass" message to be more obvious,
+       fix spaces in GOROOT (thanks Christopher Nielsen).
+* bytes: fix bug in buffer.ReadBytes (thanks Evan Shaw).
+* 5g: better int64 code,
+       don’t use MVN instruction.
+* cgo: don't run cgo when not compiling (thanks Gustavo Niemeyer),
+       fix _cgo_run timestamp file order (thanks Gustavo Niemeyer),
+       fix handling of signed enumerations (thanks Gustavo Niemeyer),
+       os/arch dependent #cgo directives (thanks Gustavo Niemeyer),
+       rename internal f to avoid conflict with possible C global named f.
+* codereview: fix hgpatch on windows (thanks Yasuhiro Matsumoto),
+       record repository, base revision,
+       use cmd.communicate (thanks Yasuhiro Matsumoto).
+* container/ring: replace Iter() with Do().
+* crypto/cipher: add resync open to OCFB mode.
+* crypto/openpgp/armor: bug fixes.
+* crypto/openpgp/packet: new subpackage.
+* crypto/tls: load a chain of certificates from a file,
+       select best cipher suite, not worst.
+* crypto/x509: add support for name constraints.
+* debug/pe: ImportedSymbols fixes (thanks Wei Guangjing).
+* doc/code: update to reflect that package names need not be unique.
+* doc/codelab/wiki: a bunch of fixes (thanks Andrey Mirtchovski).
+* doc/install: update for new versions of Mercurial.
+* encoding/line: fix line returned after EOF.
+* flag: allow hexadecimal (0xFF) and octal (0377) input for integer flags.
+* fmt.Scan: scan binary-exponent floating format, 2.4p-3,
+       hexadecimal (0xFF) and octal (0377) integers.
+* fmt: document %%; also %b for floating point.
+* gc, ld: detect stale or incompatible object files,
+       package name main no longer reserved.
+* gc: correct receiver in method missing error (thanks Lorenzo Stoakes),
+       correct rounding of denormal constants (thanks Eoghan Sherry),
+       select receive bug fix.
+* go/printer, gofmt: smarter handling of multi-line raw strings.
+* go/printer: line comments must always end in a newline,
+       remove notion of "Styler", remove HTML mode.
+* gob: allow Decode(nil) and have it just discard the next value.
+* godoc: use IsAbs to test for absolute paths (fix for win32) (thanks Yasuhiro Matsumoto),
+       don't hide package lookup error if there's no command with the same name.
+* gotest: enable unit tests for main programs.
+* http: add Server type supporting timeouts,
+       add pipelining to ClientConn, ServerConn (thanks Petar Maymounkov),
+       handle unchunked, un-lengthed HTTP/1.1 responses.
+* io: add RuneReader.
+* json: correct Marshal documentation.
+* netchan: graceful handling of closed connection (thanks Graham Miller).
+* os: implement new Process API (thanks Alex Brainman).
+* regexp tests: make some benchmarks more meaningful.
+* regexp: add support for matching against text read from RuneReader interface.
+* rpc: make more tolerant of errors, properly discard values (thanks Roger Peppe).
+* runtime: detect failed thread creation on Windows,
+       faster allocator, garbage collector,
+       fix virtual memory exhaustion,
+       implemented windows console ctrl handler (SIGINT) (thanks Hector Chu),
+       more detailed panic traces, line number work,
+       improved Windows callback handling (thanks Hector Chu).
+* spec: adjust notion of Assignability,
+       allow import of packages named main,
+       clarification re: method sets of newly declared pointer types,
+       fix a few typos (thanks Anthony Martin),
+       fix Typeof() return type (thanks Gustavo Niemeyer),
+       move to Unicode 6.0.
+* sync: diagnose Unlock of unlocked Mutex,
+       new Waitgroup type (thanks Gustavo Niemeyer).
+* syscall: add SetsockoptIpMreq (thanks Dave Cheney),
+       add sockaddr_dl, sysctl with routing message support for darwin, freebsd (thanks Mikio Hara),
+       do not use NULL for zero-length read, write,
+       implement windows version of Fsync (thanks Alex Brainman),
+       make ForkExec acquire the ForkLock under windows (thanks Hector Chu),
+       make windows API return errno instead of bool (thanks Alex Brainman),
+       remove obsolete socket IO control (thanks Mikio Hara).
+* template: add simple formatter chaining (thanks Kyle Consalus),
+       allow a leading '*' to indirect through a pointer.
+* testing: include elapsed time in test output
+* windows: replace remaining __MINGW32__ instances with _WIN32 (thanks Joe Poirier).
+
+

2011-02-01

diff --git a/doc/effective_go.html b/doc/effective_go.html
index 3f6f89b8b..8f94f467b 100644
--- a/doc/effective_go.html
+++ b/doc/effective_go.html
@@ -824,7 +824,7 @@ executions.  Here's a silly example.
 

-for i := 0; i < 5; i++ {
+for i := 0; i < 5; i++ {
     defer fmt.Printf("%d ", i)
 }
 
@@ -1486,7 +1486,7 @@ for a min function that chooses the least of a list of integers: func Min(a ...int) int { min := int(^uint(0) >> 1) // largest int for _, i := range a { - if i < min { + if i < min { min = i } } @@ -2670,7 +2670,7 @@ suppresses the usual check for a return statement. // A toy implementation of cube root using Newton's method. func CubeRoot(x float64) float64 { z := x/3 // Arbitrary intitial value - for i := 0; i < 1e6; i++ { + for i := 0; i < 1e6; i++ { prevz := z z -= (z*z*z-x) / (3*z*z) if veryClose(z, prevz) { @@ -2705,7 +2705,7 @@ func init() {

When panic is called, including implicitly for run-time -errors such indexing an array out of bounds or failing a type +errors such as indexing an array out of bounds or failing a type assertion, it immediately stops execution of the current function and begins unwinding the stack of the goroutine, running any deferred functions along the way. If that unwinding reaches the top of the @@ -2727,7 +2727,7 @@ inside a server without killing the other executing goroutines.

-func server(workChan <-chan *Work) {
+func server(workChan <-chan *Work) {
     for work := range workChan {
         go safelyDo(work)
     }
@@ -2751,7 +2751,16 @@ calling recover handles the condition completely.
 

-Note that with this recovery pattern in place, the do +Because recover always returns nil unless called directly +from a deferred function, deferred code can call library routines that themselves +use panic and recover without failing. As an example, +the deferred function in safelyDo might call a logging function before +calling recover, and that logging code would run unaffected +by the panicking state. +

+ +

+With our recovery pattern in place, the do function (and anything it calls) can get out of any bad situation cleanly by calling panic. We can use that idea to simplify error handling in complex software. Let's look at an @@ -2876,7 +2885,7 @@ func main() { } func QR(w http.ResponseWriter, req *http.Request) { - templ.Execute(req.FormValue("s"), w) + templ.Execute(w, req.FormValue("s")) } func UrlHtmlFormatter(w io.Writer, fmt string, v ...interface{}) { diff --git a/doc/go_spec.html b/doc/go_spec.html index 4e5d9c639..a95ed704a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ - +

Bootstrapping

@@ -5064,8 +4991,12 @@ The importing of packages, by construction, guarantees that there can be no cyclic dependencies in initialization.

-A complete program, possibly created by linking multiple packages, -must have one package called main, with a function +A complete program is created by linking a single, unimported package +called the main package with all the packages it imports, transitively. +The main package must +have package name main and +declare a function main that takes no +arguments and returns no value.

@@ -5073,20 +5004,12 @@ func main() { ... }
 

-defined. -The function main.main() takes no arguments and returns no value. -

-

-Program execution begins by initializing the main package and then -invoking main.main(). -

-

-When main.main() returns, the program exits. It does not wait for -other (non-main) goroutines to complete. +Program execution begins by initializing the main package and then +invoking the function main.

-Implementation restriction: The compiler assumes package main -is not imported by any other package. +When the function main returns, the program exits. +It does not wait for other (non-main) goroutines to complete.

Run-time panics

@@ -5133,8 +5056,8 @@ func Alignof(variable ArbitraryType) int func Offsetof(selector ArbitraryType) int func Sizeof(variable ArbitraryType) int -func Reflect(val interface {}) (typ runtime.Type, addr uintptr) -func Typeof(val interface {}) reflect.Type +func Reflect(val interface{}) (typ runtime.Type, addr uintptr) +func Typeof(val interface{}) (typ interface{}) func Unreflect(typ runtime.Type, addr uintptr) interface{}
diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index ece22036a..e3d946f8d 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -5,10 +5,13 @@ This document is a tutorial introduction to the basics of the Go programming language, intended for programmers familiar with C or C++. It is not a comprehensive guide to the language; at the moment the document closest to that is the language specification. -After you've read this tutorial, you might want to look at +After you've read this tutorial, you should look at Effective Go, -which digs deeper into how the language is used. -Also, slides from a 3-day course about Go are available: +which digs deeper into how the language is used and +talks about the style and idioms of programming in Go. +Also, slides from a 3-day course about Go are available. +Although they're badly out of date, they provide some +background and a lot of examples: Day 1, Day 2, Day 3. @@ -258,11 +261,11 @@ of course you can change a string variable simply by reassigning it. This snippet from strings.go is legal code:

 
-11        s := "hello"
-12        if s[1] != 'e' { os.Exit(1) }
-13        s = "good bye"
-14        var p *string = &s
-15        *p = "ciao"
+10        s := "hello"
+11        if s[1] != 'e' { os.Exit(1) }
+12        s = "good bye"
+13        var p *string = &s
+14        *p = "ciao"
 

However the following statements are illegal because they would modify diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt index 5eea3c980..2b2a0cda1 100644 --- a/doc/go_tutorial.txt +++ b/doc/go_tutorial.txt @@ -6,10 +6,13 @@ This document is a tutorial introduction to the basics of the Go programming language, intended for programmers familiar with C or C++. It is not a comprehensive guide to the language; at the moment the document closest to that is the language specification. -After you've read this tutorial, you might want to look at +After you've read this tutorial, you should look at Effective Go, -which digs deeper into how the language is used. -Also, slides from a 3-day course about Go are available: +which digs deeper into how the language is used and +talks about the style and idioms of programming in Go. +Also, slides from a 3-day course about Go are available. +Although they're badly out of date, they provide some +background and a lot of examples: Day 1, Day 2, Day 3. diff --git a/doc/htmlgen.go b/doc/htmlgen.go index 5d0bad8b5..4d68767c3 100644 --- a/doc/htmlgen.go +++ b/doc/htmlgen.go @@ -18,13 +18,13 @@ import ( ) var ( - lines = make([][]byte, 0, 10000) // assume big enough - linebuf = make([]byte, 10000) // assume big enough + lines = make([][]byte, 0, 2000) // probably big enough; grows if not empty = []byte("") newline = []byte("\n") tab = []byte("\t") quote = []byte(`"`) + indent = []byte{' ', ' ', ' ', ' '} sectionMarker = []byte("----\n") preStart = []byte("

")
@@ -52,9 +52,7 @@ func read() {
 		if err != nil {
 			log.Fatal(err)
 		}
-		n := len(lines)
-		lines = lines[0 : n+1]
-		lines[n] = line
+		lines = append(lines, line)
 	}
 }
 
@@ -173,19 +171,7 @@ func trim(l []byte) []byte {
 	return l
 }
 
-// expand tabs to 4 spaces. don't worry about columns.
+// expand tabs to spaces. don't worry about columns.
 func expandTabs(l []byte) []byte {
-	j := 0 // position in linebuf.
-	for _, c := range l {
-		if c == '\t' {
-			for k := 0; k < 4; k++ {
-				linebuf[j] = ' '
-				j++
-			}
-		} else {
-			linebuf[j] = c
-			j++
-		}
-	}
-	return linebuf[0:j]
+	return bytes.Replace(l, tab, indent, -1)
 }
diff --git a/doc/install.html b/doc/install.html
index 5917da964..d8fa8b468 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -110,6 +110,21 @@ package repository will most likely be old and broken.)
 If that fails, try installing manually from the Mercurial Download page.

+

+Mercurial versions 1.7.x and up require the configuration of +Certification Authorities +(CAs). Error messages of the form: +

+
+warning: go.googlecode.com certificate with fingerprint b1:af: ... bc not verified (check hostfingerprints or web.cacerts config setting)
+
+

+when using Mercurial indicate that the CAs are missing. +Check your Mercurial version (hg --version) and +configure the CAs +if necessary. +

+

Fetch the repository

@@ -138,8 +153,7 @@ If all goes well, it will finish by printing output like:

---- cd ../test
-N known bugs; 0 unexpected bugs
+ALL TESTS PASSED
 
 ---
 Installed Go for linux/amd64 in /home/you/go.
-- 
cgit v1.2.3