summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-02-18 09:50:58 +0100
committerOndřej Surý <ondrej@sury.org>2011-02-18 09:50:58 +0100
commitc072558b90f1bbedc2022b0f30c8b1ac4712538e (patch)
tree67767591619e4bd8111fb05fac185cde94fb7378 /doc
parent5859517b767c99749a45651c15d4bae5520ebae8 (diff)
downloadgolang-c072558b90f1bbedc2022b0f30c8b1ac4712538e.tar.gz
Imported Upstream version 2011.02.15upstream/2011.02.15
Diffstat (limited to 'doc')
-rw-r--r--doc/code.html6
-rw-r--r--doc/codelab/wiki/final.go2
-rw-r--r--doc/codelab/wiki/index.html19
-rw-r--r--doc/codelab/wiki/srcextract.go21
-rw-r--r--doc/codelab/wiki/wiki.html8
-rw-r--r--doc/devel/release.html106
-rw-r--r--doc/effective_go.html23
-rw-r--r--doc/go_spec.html211
-rw-r--r--doc/go_tutorial.html19
-rw-r--r--doc/go_tutorial.txt9
-rw-r--r--doc/htmlgen.go24
-rw-r--r--doc/install.html18
12 files changed, 258 insertions, 208 deletions
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 <code>"crypto/rot13"</code>
should be named <code>rot13</code>.
-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.
</p>
<p>
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:
</p>
<pre>
-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, &#34;/edit/&#34;+title, http.StatusFound)
@@ -658,10 +662,14 @@ Now let's fix up <code>saveHandler</code>:
</p>
<pre>
-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(&#34;body&#34;)
p := &amp;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 <code>init</code> function, which will be called before
<code>ParseFile</code> 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.
-</p
+</p>
<pre>
func init() {
@@ -726,7 +734,7 @@ the <code>Execute</code> method on the appropriate <code>Template</code> from
<pre>
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:
</p>
<pre>
+var titleValidator = regexp.MustCompile(&#34;^[a-zA-Z0-9]+$&#34;)
</pre>
<p>
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:
</p>
<pre>
-!./srcextract.bin -src=final.go -name=viewHandler
+!./srcextract.bin -src=final-noclosure.go -name=viewHandler
</pre>
<p>
@@ -539,7 +539,7 @@ Now let's fix up <code>saveHandler</code>:
</p>
<pre>
-!./srcextract.bin -src=final.go -name=saveHandler
+!./srcextract.bin -src=final-noclosure.go -name=saveHandler
</pre>
<p>
@@ -574,7 +574,7 @@ Then we create an <code>init</code> function, which will be called before
<code>ParseFile</code> 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.
-</p
+</p>
<pre>
!./srcextract.bin -src=final.go -name=init
@@ -610,7 +610,7 @@ Then we can create a global variable to store our validation regexp:
</p>
<pre>
-!./srcextract.bin -src=final-noclosure.go -name=TitleValidator
+!./srcextract.bin -src=final-noclosure.go -name=titleValidator
</pre>
<p>
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 @@
<p>This page summarizes the changes between tagged releases of Go.
For full details, see the <a href="http://code.google.com/p/go/source/list">Mercurial change log</a>.</p>
+<h3 id="2011-02-01">2011-02-15</h3>
+
+<pre>
+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).
+</pre>
+
<h3 id="2011-02-01">2011-02-01</h3>
<pre>
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.
</p>
<pre>
-for i := 0; i < 5; i++ {
+for i := 0; i &lt; 5; i++ {
defer fmt.Printf("%d ", i)
}
</pre>
@@ -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 &lt; min {
min = i
}
}
@@ -2670,7 +2670,7 @@ suppresses the usual check for a <code>return</code> 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 &lt; 1e6; i++ {
prevz := z
z -= (z*z*z-x) / (3*z*z)
if veryClose(z, prevz) {
@@ -2705,7 +2705,7 @@ func init() {
<p>
When <code>panic</code> 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.
</p>
<pre>
-func server(workChan <-chan *Work) {
+func server(workChan &lt;-chan *Work) {
for work := range workChan {
go safelyDo(work)
}
@@ -2751,7 +2751,16 @@ calling <code>recover</code> handles the condition completely.
</p>
<p>
-Note that with this recovery pattern in place, the <code>do</code>
+Because <code>recover</code> always returns <code>nil</code> unless called directly
+from a deferred function, deferred code can call library routines that themselves
+use <code>panic</code> and <code>recover</code> without failing. As an example,
+the deferred function in <code>safelyDo</code> might call a logging function before
+calling <code>recover</code>, and that logging code would run unaffected
+by the panicking state.
+</p>
+
+<p>
+With our recovery pattern in place, the <code>do</code>
function (and anything it calls) can get out of any bad situation
cleanly by calling <code>panic</code>. 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 @@
<!-- title The Go Programming Language Specification -->
-<!-- subtitle Version of February 1, 2011 -->
+<!-- subtitle Version of February 8, 2011 -->
<!--
TODO
@@ -104,12 +104,12 @@ The following terms are used to denote specific Unicode character classes:
<pre class="ebnf">
unicode_char = /* an arbitrary Unicode code point */ .
unicode_letter = /* a Unicode code point classified as "Letter" */ .
-unicode_digit = /* a Unicode code point classified as "Digit" */ .
+unicode_digit = /* a Unicode code point classified as "Decimal Digit" */ .
</pre>
<p>
-In <a href="http://www.unicode.org/versions/Unicode5.2.0/">The Unicode Standard 5.2</a>,
-Section 4.5 General Category-Normative
+In <a href="http://www.unicode.org/versions/Unicode6.0.0/">The Unicode Standard 6.0</a>,
+Section 4.5 "General Category"
defines a set of character categories. Go treats
those characters in category Lu, Ll, Lt, Lm, or Lo as Unicode letters,
and those in category Nd as Unicode digits.
@@ -610,6 +610,17 @@ type literals.
</p>
<p>
+The <i>static type</i> (or just <i>type</i>) of a variable is the
+type defined by its declaration. Variables of interface type
+also have a distinct <i>dynamic type</i>, which
+is the actual type of the value stored in the variable at run-time.
+The dynamic type may vary during execution but is always
+<a href="#Assignability">assignable</a>
+to the static type of the interface variable. For non-interface
+types, the dynamic type is always the static type.
+</p>
+
+<p>
Each type <code>T</code> has an <i>underlying type</i>: If <code>T</code>
is a predeclared type or a type literal, the corresponding underlying
type is <code>T</code> itself. Otherwise, <code>T</code>'s underlying type
@@ -630,6 +641,7 @@ is <code>string</code>. The underlying type of <code>[]T1</code>, <code>T3</code
and <code>T4</code> is <code>[]T1</code>.
</p>
+<h3 id="Method_sets">Method sets</h3>
<p>
A type may have a <i>method set</i> associated with it
(§<a href="#Interface_types">Interface types</a>, §<a href="#Method_declarations">Method declarations</a>).
@@ -642,16 +654,6 @@ is the set of all methods with receiver <code>*T</code> or <code>T</code>
Any other type has an empty method set.
In a method set, each method must have a unique name.
</p>
-<p>
-The <i>static type</i> (or just <i>type</i>) of a variable is the
-type defined by its declaration. Variables of interface type
-also have a distinct <i>dynamic type</i>, which
-is the actual type of the value stored in the variable at run-time.
-The dynamic type may vary during execution but is always
-<a href="#Assignability">assignable</a>
-to the static type of the interface variable. For non-interface
-types, the dynamic type is always the static type.
-</p>
<h3 id="Boolean_types">Boolean types</h3>
@@ -917,7 +919,8 @@ a type named <code>T</code>:
</p>
<ul>
<li>If <code>S</code> contains an anonymous field <code>T</code>, the
- method set of <code>S</code> includes the method set of <code>T</code>.
+ <a href="#Method_sets">method set</a> of <code>S</code> includes the
+ method set of <code>T</code>.
</li>
<li>If <code>S</code> contains an anonymous field <code>*T</code>, the
@@ -1016,7 +1019,7 @@ func(n int) func(p *T)
<h3 id="Interface_types">Interface types</h3>
<p>
-An interface type specifies a <a href="#Types">method set</a> called its <i>interface</i>.
+An interface type specifies a <a href="#Method_sets">method set</a> called its <i>interface</i>.
A variable of interface type can store a value of any type with a method set
that is any superset of the interface. Such a type is said to
<i>implement the interface</i>.
@@ -1349,11 +1352,12 @@ by a value of type <code>T</code>.
</ul>
<p>
-If <code>T</code> is a struct type, either all fields of <code>T</code>
-must be <a href="#Exported_identifiers">exported</a>, or the assignment must be in
-the same package in which <code>T</code> is declared.
+If <code>T</code> is a struct type with non-<a href="#Exported_identifiers">exported</a>
+fields, the assignment must be in the same package in which <code>T</code> is declared,
+or <code>x</code> must be the receiver of a method call.
In other words, a struct value can be assigned to a struct variable only if
-every field of the struct may be legally assigned individually by the program.
+every field of the struct may be legally assigned individually by the program,
+or if the assignment is initializing the receiver of a method of the struct type.
</p>
<p>
@@ -1677,7 +1681,7 @@ type Cipher interface {
<p>
The declared type does not inherit any <a href="#Method_declarations">methods</a>
-bound to the existing type, but the <a href="#Types">method set</a>
+bound to the existing type, but the <a href="#Method_sets">method set</a>
of an interface type or of elements of a composite type remains unchanged:
</p>
@@ -1690,6 +1694,10 @@ func (m *Mutex) Unlock() { /* Unlock implementation */ }
// NewMutex has the same composition as Mutex but its method set is empty.
type NewMutex Mutex
+// The method set of the <a href="#Pointer_types">base type</a> of PtrMutex remains unchanged,
+// but the method set of PtrMutex is empty.
+type PtrMutex *Mutex
+
// The method set of *PrintableMutex contains the methods
// Lock and Unlock bound to its anonymous field Mutex.
type PrintableMutex struct {
@@ -2593,8 +2601,8 @@ if Join(Split(value, len(value)/2)) != value {
</pre>
<p>
-A method call <code>x.m()</code> is valid if the method set of
-(the type of) <code>x</code> contains <code>m</code> and the
+A method call <code>x.m()</code> is valid if the <a href="#Method_sets">method set</a>
+of (the type of) <code>x</code> contains <code>m</code> and the
argument list can be assigned to the parameter list of <code>m</code>.
If <code>x</code> is <a href="#Address_operators">addressable</a> and <code>&amp;x</code>'s method
set contains <code>m</code>, <code>x.m()</code> is shorthand
@@ -2889,8 +2897,8 @@ Comparison operators compare two operands and yield a value of type <code>bool</
<pre class="grammar">
== equal
!= not equal
-< less
-<= less or equal
+&lt; less
+&lt;= less or equal
> greater
>= greater or equal
</pre>
@@ -3057,7 +3065,7 @@ need to be presented regarding send, receive, select, and goroutines.</span>
<h3 id="Method_expressions">Method expressions</h3>
<p>
-If <code>M</code> is in the method set of type <code>T</code>,
+If <code>M</code> is in the <a href="#Method_sets">method set</a> of type <code>T</code>,
<code>T.M</code> is a function that is callable as a regular function
with the same arguments as <code>M</code> prefixed by an additional
argument that is the receiver of the method.
@@ -4004,7 +4012,7 @@ the channel until the channel is closed; it does not produce the zero value sent
before the channel is closed
(§<a href="#Close_and_closed"><code>close</code> and <code>closed</code></a>).
</li>
-</ol
+</ol>
<p>
The iteration values are assigned to the respective
@@ -4436,7 +4444,7 @@ At any time the following relationship holds:
</p>
<pre>
-0 <= len(s) <= cap(s)
+0 &lt;= len(s) &lt;= cap(s)
</pre>
<p>
@@ -4646,13 +4654,6 @@ func recover() interface{}
</pre>
<p>
-<span class="alert">TODO: Most of this text could move to the respective
-comments in <code>runtime.go</code> once the functions are implemented.
-They are here, at least for now, for reference and discussion.
-</span>
-</p>
-
-<p>
When a function <code>F</code> calls <code>panic</code>, normal
execution of <code>F</code> stops immediately. Any functions whose
execution was <a href="#Defer_statements">deferred</a> by the
@@ -4667,117 +4668,43 @@ the argument to <code>panic</code>. This termination sequence is
called <i>panicking</i>.
</p>
+<pre>
+panic(42)
+panic("unreachable")
+panic(Error("cannot parse"))
+</pre>
+
<p>
The <code>recover</code> function allows a program to manage behavior
of a panicking goroutine. Executing a <code>recover</code> call
-inside a deferred function (but not any function called by it) stops
+<i>inside</i> a deferred function (but not any function called by it) stops
the panicking sequence by restoring normal execution, and retrieves
the error value passed to the call of <code>panic</code>. If
<code>recover</code> is called outside the deferred function it will
-not stop a panicking sequence. In this case, and when the goroutine
-is not panicking, <code>recover</code> returns <code>nil</code>.
+not stop a panicking sequence. In this case, or when the goroutine
+is not panicking, or if the argument supplied to <code>panic</code>
+was <code>nil</code>, <code>recover</code> returns <code>nil</code>.
</p>
<p>
-If the function defined here,
+The <code>protect</code> function in the example below invokes
+the function argument <code>g</code> and protects callers from
+run-time panics raised by <code>g</code>.
</p>
<pre>
-func f(hideErrors bool) {
+func protect(g func()) {
defer func() {
+ log.Println("done") // Println executes normally even in there is a panic
if x := recover(); x != nil {
- println("panicking with value", x)
- if !hideErrors {
- panic(x) // go back to panicking
- }
- }
- println("function returns normally") // executes only when hideErrors==true
- }()
- println("before")
- p()
- println("after") // never executes
-}
-
-func p() {
- panic(3)
-}
-</pre>
-
-<p>
-is called with <code>hideErrors=true</code>, it prints
-</p>
-
-<pre>
-before
-panicking with value 3
-function returns normally
-</pre>
-
-<p>
-and resumes normal execution in the function that called <code>f</code>. Otherwise, it prints
-</p>
-
-<pre>
-before
-panicking with value 3
-</pre>
-
-<p>
-and, absent further <code>recover</code> calls, terminates the program.
-</p>
-
-<p>
-Since deferred functions run before assigning the return values to the caller
-of the deferring function, a deferred invocation of a function literal may modify the
-invoking function's return values in the event of a panic. This permits a function to protect its
-caller from panics that occur in functions it calls.
-</p>
-
-<pre>
-func IsPrintable(s string) (ok bool) {
- ok = true
- defer func() {
- if recover() != nil {
- println("input is not printable")
- ok = false
+ log.Printf("runtime panic: %v", x)
}
- // Panicking has stopped; execution will resume normally in caller.
- // The return value will be true normally, false if a panic occurred.
- }()
- panicIfNotPrintable(s) // will panic if validations fails.
- return
-}
-</pre>
-
-<!---
-<p>
-A deferred function that calls <code>recover</code> will see the
-argument passed to <code>panic</code>. However, functions called
-<i>from</i> the deferred function run normally, without behaving as
-though they are panicking. This allows deferred code to run normally
-in case recovery is necessary and guarantees that functions that manage
-their own panics will not fail incorrectly. The function
-</p>
-
-<pre>
-func g() {
- s := ReadString()
- defer func() {
- if IsPrintable(s) {
- println("finished processing", s)
- } else {
- println("finished processing unprintable string")
- }
- }()
- Analyze(s)
+ }
+ log.Println("start")
+ g()
}
</pre>
-<p>
-will not cause <code>IsPrintable</code> to print <code>"input is not printable"</code>
-due to a <code>panic</code> triggered by the call to <code>Analyze</code>.
-</p>
--->
<h3 id="Bootstrapping">Bootstrapping</h3>
@@ -5064,8 +4991,12 @@ The importing of packages, by construction, guarantees that there can
be no cyclic dependencies in initialization.
</p>
<p>
-A complete program, possibly created by linking multiple packages,
-must have one package called <code>main</code>, with a function
+A complete program is created by linking a single, unimported package
+called the <i>main package</i> with all the packages it imports, transitively.
+The main package must
+have package name <code>main</code> and
+declare a function <code>main</code> that takes no
+arguments and returns no value.
</p>
<pre>
@@ -5073,20 +5004,12 @@ func main() { ... }
</pre>
<p>
-defined.
-The function <code>main.main()</code> takes no arguments and returns no value.
-</p>
-<p>
-Program execution begins by initializing the <code>main</code> package and then
-invoking <code>main.main()</code>.
-</p>
-<p>
-When <code>main.main()</code> returns, the program exits. It does not wait for
-other (non-<code>main</code>) goroutines to complete.
+Program execution begins by initializing the main package and then
+invoking the function <code>main</code>.
</p>
<p>
-Implementation restriction: The compiler assumes package <code>main</code>
-is not imported by any other package.
+When the function <code>main</code> returns, the program exits.
+It does not wait for other (non-<code>main</code>) goroutines to complete.
</p>
<h2 id="Run_time_panics">Run-time panics</h2>
@@ -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{}
</pre>
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
<a href='/doc/go_spec.html'>language specification</a>.
-After you've read this tutorial, you might want to look at
+After you've read this tutorial, you should look at
<a href='/doc/effective_go.html'>Effective Go</a>,
-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:
<a href='/doc/GoCourseDay1.pdf'>Day 1</a>,
<a href='/doc/GoCourseDay2.pdf'>Day 2</a>,
<a href='/doc/GoCourseDay3.pdf'>Day 3</a>.
@@ -258,11 +261,11 @@ 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> <!-- progs/strings.go /hello/ /ciao/ -->
-11 s := &quot;hello&quot;
-12 if s[1] != 'e' { os.Exit(1) }
-13 s = &quot;good bye&quot;
-14 var p *string = &amp;s
-15 *p = &quot;ciao&quot;
+10 s := &quot;hello&quot;
+11 if s[1] != 'e' { os.Exit(1) }
+12 s = &quot;good bye&quot;
+13 var p *string = &amp;s
+14 *p = &quot;ciao&quot;
</pre>
<p>
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
<a href='/doc/go_spec.html'>language specification</a>.
-After you've read this tutorial, you might want to look at
+After you've read this tutorial, you should look at
<a href='/doc/effective_go.html'>Effective Go</a>,
-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:
<a href='/doc/GoCourseDay1.pdf'>Day 1</a>,
<a href='/doc/GoCourseDay2.pdf'>Day 2</a>,
<a href='/doc/GoCourseDay3.pdf'>Day 3</a>.
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("<pre>")
@@ -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 <a href="http://mercurial.selenic.com/wiki/Download">Mercurial Download</a> page.</p>
</p>
+<p>
+Mercurial versions 1.7.x and up require the configuration of
+<a href="http://mercurial.selenic.com/wiki/CACertificates">Certification Authorities</a>
+(CAs). Error messages of the form:
+</p>
+<pre>
+warning: go.googlecode.com certificate with fingerprint b1:af: ... bc not verified (check hostfingerprints or web.cacerts config setting)
+</pre>
+<p>
+when using Mercurial indicate that the CAs are missing.
+Check your Mercurial version (<code>hg --version</code>) and
+<a href="http://mercurial.selenic.com/wiki/CACertificates#Configuration_of_HTTPS_certificate_authorities">configure the CAs</a>
+if necessary.
+</p>
+
<h2 id="fetch">Fetch the repository</h2>
<p>
@@ -138,8 +153,7 @@ If all goes well, it will finish by printing output like:
</p>
<pre>
---- cd ../test
-N known bugs; 0 unexpected bugs
+ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/you/go.