From 6e7a55a2c0ab461fd1c8e68c3c7366b0afa4d4d4 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg
-Godoc treats executable commands somewhat differently. Instead of inspecting the
-command source code, it looks for a Go source file belonging to the special
-package "documentation". The comment on the "package documentation" clause is
-used as the command's documentation. For example, see the
+Godoc treats executable commands in the same way. It looks for a comment on
+package main, which is sometimes put in a separate file called
-Data races are one of the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write. See the The Go Memory Model for details.
+Data races are among the most common and hardest to debug types of bugs in concurrent systems.
+A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write.
+See the The Go Memory Model for details.
@@ -32,7 +34,8 @@ func main() {
-Fortunately, Go includes a built-in data race detector. To use it, add the
-When the race detector finds a data race in the program, it prints a report. The report contains stack traces for conflicting accesses, as well as stacks where the involved goroutines were created. For example:
+When the race detector finds a data race in the program, it prints a report.
+The report contains stack traces for conflicting accesses, as well as stacks where the involved goroutines were created.
+Here is an example:
-The
-When you build with
To start, run your tests using the race detector (
The variable
-The fix is to introduce new variables in the goroutines (note
-If the following code is called from several goroutines, it leads to bad races on the
-Data races can happen on variables of primitive types as well (
-Even such “innocent” data races can lead to hard to debug problems caused by (1) non-atomicity of the memory accesses, (2) interference with compiler optimizations and (3) processor memory access reordering issues.
+Even such "innocent" data races can lead to hard-to-debug problems caused by
+non-atomicity of the memory accesses,
+interference with compiler optimizations,
+or reordering issues accessing processor memory .
A typical fix for this race is to use a channel or a mutex.
-To preserve the lock-free behavior, one can also use the
This document demonstrates the development of a simple Go package and
-introduces the go command, the standard way to fetch,
+introduces the go tool, the standard way to fetch,
build, and install Go packages and commands.
-This content is also available as a screencast.
+The
+A similar explanation is available as a
+screencast.
-One of Go's design goals is to make writing software easier. To that end, the
-
-The one thing you must do is set a
-
-(On a Windows system use semicolons as the path separator instead of colons.)
+The
-Each path in the list (in this case
-Subdirectories of the
-When building a program that imports the package "
-Multiple workspaces can offer some flexibility and convenience, but for now
-we'll concern ourselves with only a single workspace.
+The
-Let's work through a simple example. First, create a
-Next, set it as the
-The standard packages are given short import paths such as
-The best way to choose an import path is to use the location of your version
-control repository.
-For instance, if your source repository is at
-If you don't intend to install your code in this way, you should at
-least use a unique prefix like "
-We'll use
-The first statement in a Go source file should be
+To compile and run a simple program, first choose a package path (we'll use
+
-where
-Go's convention is that the package name is the last element of the
-import path: the package imported as "
-Create a new package under
-Then create a file named
-This package is imported by the path name of the directory it's in, starting
-after the
+You can also omit the package path if you run
-See Effective Go to learn more about
-Go's naming conventions.
+This command builds the
+The
-The
-To "install a package" means to write the package object or executable command
-to the
-To build and install the
-This command will produce no output if the package and its dependencies
-are built and installed correctly.
+Pushing the code to a remote repository is left as an exercise for the reader.
+
+Let's write a library and use it from the
-As a convenience, the
-The resulting workspace directory tree (assuming we're running Linux on a 64-bit
-system) looks like this:
+Next, create a file named
-The
-Add a command named
-Then create the file
+After confirming that the
-Next, run
-To run the program, invoke it by name as you would any other command:
+the
-If you added
-The workspace directory tree now looks like this:
+After the steps above, your workspace should look like this:
-The
+Go command executables are statically linked; the package objects need not
+be present to run Go programs.
+
+The first statement in a Go source file must be
+
+where
+Go's convention is that the package name is the last element of the
+import path: the package imported as "
+Executable commands must always use
+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.
+
+See Effective Go to learn more about
+Go's naming conventions.
Add a test to the
-Now run the test with
+As always, if you are running the
@@ -415,7 +504,7 @@ Run
An import path can describe how to obtain the package source code using a
-revision control system such as Git or Mercurial. The
This convention is the easiest way to make your Go packages available for
others to use.
-The Go Community Wiki
-has a list of external Go projects including programs and libraries.
+The Go Wiki
+and godoc.org
+provide lists of external Go projects.
-For more information on using remote repositories with the bytes
packa
doc.go
.
+For example, see the
godoc documentation and its corresponding
doc.go file.
Introduction
Usage
-race
flag to the go command:
+To help diangose such bugs, Go includes a built-in data race detector.
+To use it, add the -race
flag to the go command:
@@ -45,7 +48,9 @@ $ go install -race mypkg // to install the package
Report Format
@@ -86,7 +91,8 @@ Goroutine 184 (running) created at:
Options
GORACE
environment variable sets race detector options. The format is:
+The GORACE
environment variable sets race detector options.
+The format is:
@@ -100,7 +106,8 @@ The options are:
@@ -134,9 +141,10 @@ $ GORACE="log_path=/tmp/race/report strip_path_prefix=/my/go/sources/" go test -
log_path
(default stderr
): The race detector writes
-its report to a file named log_path.pid. The special names stdout
+its report to a file named log_path.pid
.
+The special names stdout
and stderr
cause reports to be written to standard output and
standard error, respectively.
history_size
(default 1
): The per-goroutine memory
-access history is 32K * 2**history_size elements
. Increasing this
-value can avoid a "failed to restore the stack" error in reports, but at the
+access history is 32K * 2**history_size elements
.
+Increasing this value can avoid a "failed to restore the stack" error in reports, at the
cost of increased memory usage.
Excluding Tests
-race
flag, go command defines additional
+When you build with -race
flag, the go
command defines additional
build tag race
.
-You can use it to exclude some code/tests under the race detector. For example:
+You can use the tag to exclude some code and tests when running the race detector.
+Some examples:
@@ -165,7 +173,8 @@ func TestBaz(t *testing.T) {
go test -race
).
The race detector only finds races that happen at runtime, so it can't find
-races in code paths that are not executed. If your tests have incomplete coverage,
+races in code paths that are not executed.
+If your tests have incomplete coverage,
you may find more races by running a binary built with -race
under a realistic
workload.
i
in the function literal is the same variable used by the loop, so
-the read in the goroutine races with the loop increment. (This program typically
-prints 55555, not 01234.) The program can be fixed by making a copy of the
-variable:
+the read in the goroutine races with the loop increment.
+(This program typically prints 55555, not 01234.)
+The program can be fixed by making a copy of the variable:
@@ -246,7 +255,7 @@ func ParallelWrite(data []byte) chan error {
:=
):
+The fix is to introduce new variables in the goroutines (note the use of :=
):
@@ -260,8 +269,8 @@ The fix is to introduce new variables in the goroutines (note
:=
):
Unprotected global variable
service
map.
-Concurrent reads and writes of a map are not safe:
+If the following code is called from several goroutines, it leads to races on the service
map.
+Concurrent reads and writes of the same map are not safe:
@@ -302,7 +311,8 @@ func LookupService(name string) net.Addr {
Primitive unprotected variable
bool
, int
, int64
, etc.), like in the following example:
+Data races can happen on variables of primitive types as well (bool
, int
, int64
, etc.),
+as in this example:
@@ -327,12 +337,16 @@ func (w *Watchdog) Start() {
sync/atomic
package.
+To preserve the lock-free behavior, one can also use the
+sync/atomic
package.
diff --git a/doc/code.html b/doc/code.html
index 82b211870..2d63d4dc9 100644
--- a/doc/code.html
+++ b/doc/code.html
@@ -6,344 +6,381 @@
go
tool requires you to organize your code in a specific
+way. Please read this document carefully.
+It explains the simplest way to get up and running with your Go installation.
+Code organization
+Code organization
-
+GOPATH
and workspacesWorkspaces
go
command doesn't use Makefiles or other configuration files to
-guide program construction. Instead, it uses the source code to find
-dependencies and determine build conditions. This means your source code and
-build scripts are always in sync; they are one and the same.
+The go
tool is designed to work with open source code maintained
+in public repositories. Although you don't need to publish your code, the model
+for how the environment is set up works the same whether you do or not.
GOPATH
environment variable.
-GOPATH
tells the go
command (and other related tools)
-where to find and install the Go packages on your system.
+Go code must be kept inside a workspace.
+A workspace is a directory hierarchy with three directories at its root:
+
+
src
contains Go source files organized into packages (one package per directory),
+pkg
contains package objects, and
+bin
contains executable commands.
+GOPATH
is a list of paths. It shares the syntax of your system's
-PATH
environment variable. A typical GOPATH
on
-a Unix system might look like this:
+The go
tool builds source packages and installs the resulting
+binaries to the pkg
and bin
directories.
-GOPATH=/home/user/ext:/home/user/mygo
-
-
src
subdirectory typically contains multiple version control
+repositories (such as for Git or Mercurial) that track the development of one
+or more source packages.
/home/user/ext
or
-/home/user/mygo
) specifies the location of a workspace.
-A workspace contains Go source files and their associated package objects, and
-command executables. It has a prescribed structure of three subdirectories:
+To give you an idea of how a workspace looks in practice, here's an example:
-
+src
contains Go source files,
-pkg
contains compiled package objects, and
-bin
contains executable commands.
-
+bin/
+ streak # command executable
+ todo # command executable
+pkg/
+ linux_amd64/
+ code.google.com/p/goauth2/
+ oauth.a # package object
+ github.com/nf/todo/
+ task.a # package object
+src/
+ code.google.com/p/goauth2/
+ .hg/ # mercurial repository metadata
+ oauth/
+ oauth.go # package source
+ oauth_test.go # test source
+ github.com/nf/
+ streak/
+ .git/ # git repository metadata
+ oauth.go # command source
+ streak.go # command source
+ todo/
+ .git/ # git repository metadata
+ task/
+ task.go # package source
+ todo.go # command source
+
src
directory hold independent packages, and
-all source files (.go
, .c
, .h
, and
-.s
) in each subdirectory are elements of that subdirectory's
-package.
+This workspace contains three repositories (goauth2
,
+streak
, and todo
) comprising two commands
+(streak
and todo
) and two libraries
+(oauth
and task
).
widget
" the
-go
command looks for src/pkg/widget
inside the Go root,
-and then—if the package source isn't found there—it searches
-for src/widget
inside each workspace in order.
+Commands and libraries are built from different kinds of source packages.
+We will discuss the distinction later.
The
+
GOPATH
environment variableGOPATH
environment variable specifies the location of your
+workspace. It is likely the only environment variable you'll need to set
+when developing Go code.
$HOME/mygo
-directory and its src
subdirectory:
+To get started, create a workspace directory and set GOPATH
+accordingly. Your workspace can be located wherever you like, but we'll use
+$HOME/go
in this document. Note that this must not be the
+same path as your Go installation.
-$ mkdir -p $HOME/mygo/src # create a place to put source code
+$ mkdir $HOME/go
+$ export GOPATH=$HOME/go
GOPATH
. You should also add the
-bin
subdirectory to your PATH
environment variable so
-that you can run the commands therein without specifying their full path.
-To do this, add the following lines to $HOME/.profile
(or
-equivalent):
+For convenience, add the workspace's bin
subdirectory
+to your PATH
:
-export GOPATH=$HOME/mygo
-export PATH=$PATH:$HOME/mygo/bin
+$ export PATH=$PATH:$GOPATH/bin
-Import paths
+Package paths
"fmt"
-and "net/http"
for convenience.
-For your own projects, it is important to choose a base import path that is
-unlikely to collide with future additions to the standard library or other
-external libraries.
+The packages from the standard library are given short paths such as
+"fmt"
and "net/http"
.
+For your own packages, you must choose a base path that is unlikely to
+collide with future additions to the standard library or other external
+libraries.
example.com
-or code.google.com/p/example
, you should begin your package
-paths with that URL, as in "example.com/foo/bar
" or
-"code.google.com/p/example/foo/bar
".
-Using this convention, the go
command can automatically check out and
-build the source code by its import path alone.
+If you keep your code in a source repository somewhere, then you should use the
+root of that source repository as your base path.
+For instance, if you have a GitHub account at
+github.com/user
, that should be your base path.
widgets/
", as in
-"widgets/foo/bar
". A good rule is to use a prefix such as your
-company or project name, since it is unlikely to be used by another group.
+Note that you don't need to publish your code to a remote repository before you
+can build it. It's just a good habit to organize your code as if you will
+publish it someday. In practice you can choose any arbitrary path name,
+as long as it is unique to the standard library and greater Go ecosystem.
example/
as our base import path:
+We'll use github.com/user
as our base path. Create a directory
+inside your workspace in which to keep source code:
-$ mkdir -p $GOPATH/src/example
+$ mkdir -p $GOPATH/src/github.com/user
-Package names
+Your first program
github.com/user/hello
) and create a corresponding package directory
+inside your workspace:
-package name
+$ mkdir $GOPATH/src/github.com/user/hello
name
is the package's default name for imports.
-(All files in a package must use the same name
.)
+Next, create a file named hello.go
inside that directory,
+containing the following Go code.
crypto/rot13
"
-should be named rot13
.
-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.
-
+package main
-
example
called newmath
:
-
-$ cd $GOPATH/src/example
-$ mkdir newmath
+func main() {
+ fmt.Printf("Hello, world.\n")
+}
$GOPATH/src/example/newmath/sqrt.go
-containing the following Go code:
+Now you can build and install that program with the go
tool:
-// Package newmath is a trivial example package.
-package newmath
-
-// Sqrt returns an approximation to the square root of x.
-func Sqrt(x float64) float64 {
- // This is a terrible implementation.
- // Real code should import "math" and use math.Sqrt.
- z := 0.0
- for i := 0; i < 1000; i++ {
- z -= (z*z - x) / (2 * x)
- }
- return z
-}
+$ go install github.com/user/hello
src
component:
+Note that you can run this command from anywhere on your system. The
+go
tool finds the source code by looking for the
+github.com/user/hello
package inside the workspace specified by
+GOPATH
.
+go install
from the
+package directory:
-import "example/newmath"
+$ cd $GOPATH/src/github.com/user/hello
+$ go install
hello
command, producing an executable
+binary. It then installs that binary to the workspace's bin
+directory as hello
(or, under Windows, hello.exe
).
+In our example, that will be $GOPATH/bin/hello
, which is
+$HOME/go/bin/hello
.
Building and installing
+go
tool will only print output when an error occurs, so if
+these commands produce no output they have executed successfully.
+go
command comprises several subcommands, the most central being
-install
. Running go install importpath
builds
-and installs a package and its dependencies.
+You can now run the program by typing its full path at the command line:
+$ $GOPATH/bin/hello
+Hello, world.
+
+
pkg
or bin
subdirectory of the workspace in
-which the source resides.
+Or, as you have added $GOPATH/bin
to your PATH
,
+just type the binary name:
Building a package
+
+$ hello
+Hello, world.
+
newmath
package, type
+If you're using a source control system, now would be a good time to initialize
+a repository, add the files, and commit your first change. Again, this step is
+optional: you do not need to use source control to write Go code.
-$ go install example/newmath
+$ cd $GOPATH/src/github.com/user/hello
+$ git init
+Initialized empty Git repository in /home/user/go/src/github.com/user/hello/.git/
+$ git add hello.go
+$ git commit -m "initial commit"
+[master (root-commit) 0b4507d] initial commit
+ 1 file changed, 1 insertion(+)
+ create mode 100644 hello.go
Your first library
+
+hello
program.
go
command will assume the current directory
-if no import path is specified on the command line. This sequence of commands
-has the same effect as the one above:
+Again, the first step is to choose a package path (we'll use
+github.com/user/newmath
) and create the package directory:
-$ cd $GOPATH/src/example/newmath
-$ go install
+$ mkdir $GOPATH/src/github.com/user/newmath
sqrt.go
in that directory with the
+following contents.
-pkg/
- linux_amd64/
- example/
- newmath.a # package object
-src/
- example/
- newmath/
- sqrt.go # package source
-
-
+// Package newmath is a trivial example package.
+package newmath
-Building a command
+// Sqrt returns an approximation to the square root of x.
+func Sqrt(x float64) float64 {
+ z := 0.0
+ for i := 0; i < 1000; i++ {
+ z -= (z*z - x) / (2 * x)
+ }
+ return z
+}
+go
command treats code belonging to package main
as
-an executable command and installs the package binary to the
-GOPATH
's bin
subdirectory.
+Now, test that the package compiles with go build
:
+$ go build github.com/user/newmath
+
+
hello
to the source tree.
-First create the example/hello
directory:
+Or, if you are working in the package's source directory, just:
-$ cd $GOPATH/src/example
-$ mkdir hello
+$ go build
$GOPATH/src/example/hello/hello.go
-containing the following Go code.
+This won't produce an output file. To do that, you must use go
+install
, which places the package object inside the pkg
+directory of the workspace.
+newmath
package builds,
+modify your original hello.go
(which is in
+$GOPATH/src/github.com/user/hello
) to use it:
-// Hello is a trivial example of a main package.
package main
import (
- "example/newmath"
- "fmt"
+ "fmt"
+
+ "github.com/user/newmath"
)
func main() {
- fmt.Printf("Hello, world. Sqrt(2) = %v\n", newmath.Sqrt(2))
+ fmt.Printf("Hello, world. Sqrt(2) = %v\n", newmath.Sqrt(2))
}
go install
, which builds and installs the binary to
-$GOPATH/bin
(or $GOBIN
, if set; to simplify
-presentation, this document assumes GOBIN
is unset):
+Whenever the go
tool installs a package or binary, it also
+installs whatever dependencies it has. So when you install the hello
+program
-$ go install example/hello
+$ go install github.com/user/hello
newmath
package will be installed as well, automatically.
-$ $GOPATH/bin/hello
-Hello, world. Sqrt(2) = 1.414213562373095
-
-
$HOME/mygo/bin
to your PATH
, you may omit
-the path to the executable:
+Running the new version of the program, you should see some numerical output:
-$ hello
+$ hello
Hello, world. Sqrt(2) = 1.414213562373095
bin/
hello # command executable
pkg/
- linux_amd64/
- example/
+ linux_amd64/ # this will reflect your OS and architecture
+ github.com/user/
newmath.a # package object
src/
- example/
+ github.com/user/
hello/
hello.go # command source
newmath/
@@ -351,13 +388,55 @@ src/
go
command also provides a build
command, which is
-like install
except it builds all objects in a temporary directory
-and does not install them under pkg
or bin
.
-When building a command an executable named after the last element of the
-import path is written to the current directory. When building a package,
-go build
serves merely to test that the package and its
-dependencies can be built. (The resulting package object is thrown away.)
+Note that go install
placed the newmath.a
object in a
+directory inside pkg/linux_amd64
that mirrors its source
+directory.
+This is so that future invocations of the go
tool can find the
+package object and avoid recompiling the package unnecessarily.
+The linux_amd64
part is there to aid in cross-compilation,
+and will reflect the operating system and architecture of your system.
+Package names
+
+
+package name
+
+
+name
is the package's default name for imports.
+(All files in a package must use the same name
.)
+crypto/rot13
"
+should be named rot13
.
+package main
.
+t.Error
or
newmath
package by creating the file
-$GOPATH/src/example/newmath/sqrt_test.go
containing the following
-Go code.
+$GOPATH/src/github.com/user/newmath/sqrt_test.go
containing the
+following Go code.
@@ -397,12 +476,22 @@ func TestSqrt(t *testing.T) {
go test
:
+Then run the test with go test
:
+
+$ go test github.com/user/newmath
+ok github.com/user/newmath 0.165s
+
+
+go
tool from the package
+directory, you can omit the package path:
-$ go test example/newmath
-ok example/newmath 0.165s
+$ go test
+ok github.com/user/newmath 0.165s
go help test
and see t
go
command uses
+revision control system such as Git or Mercurial. The go
tool uses
this property to automatically fetch packages from remote repositories.
For instance, the examples described in this document are also kept in a
Mercurial repository hosted at Google Code,
@@ -425,8 +514,8 @@ If you include the repository URL in the package's import path,
-$ go get code.google.com/p/go.example/hello
-$ $GOPATH/bin/hello
+$ go get code.google.com/p/go.example/hello
+$ $GOPATH/bin/hello
Hello, world. Sqrt(2) = 1.414213562373095
@@ -446,10 +535,10 @@ tree should now now look like this:
bin/
hello # command executable
pkg/
- linux_amd64/
+ linux_amd64/
code.google.com/p/go.example/
newmath.a # package object
- example/
+ github.com/user/
newmath.a # package object
src/
code.google.com/p/go.example/
@@ -458,7 +547,7 @@ src/
newmath/
sqrt.go # package source
sqrt_test.go # test source
- example/
+ github.com/user/
hello/
hello.go # command source
newmath/
@@ -480,12 +569,13 @@ import "code.google.com/p/go.example/newmath"
go
command, see
+For more information on using remote repositories with the go
tool, see
go help remote
.
p := Prefix{"I", "am"}
-copy(p, p[:1])
+copy(p, p[1:])
// p == Prefix{"am", "am"}
We then assign the provided word
to the last index
of the slice:
diff --git a/doc/effective_go.html b/doc/effective_go.html
index decca34b5..a1e13c0f6 100644
--- a/doc/effective_go.html
+++ b/doc/effective_go.html
@@ -2466,7 +2466,7 @@ only to have them be needed again later.
The blank identifier provides a workaround.
-This half-written program is has two unused imports
+This half-written program has two unused imports
(fmt
and io
)
and an unused variable (fd
),
so it will not compile, but it would be nice to see if the
diff --git a/doc/go1.1.html b/doc/go1.1.html
index f1d490f41..fac922910 100644
--- a/doc/go1.1.html
+++ b/doc/go1.1.html
@@ -6,9 +6,41 @@
+The release of Go version 1 (Go 1 or Go 1.0 for short) +in March of 2012 introduced a new period +of stability in the Go language and libraries. +That stability has helped nourish a growing community of Go users +and systems around the world. +Several "point" releases since +then—1.0.1, 1.0.2, and 1.0.3—have been issued. +These point releases fixed known bugs but made +no non-critical changes to the implementation. +
+ ++This new release, Go 1.1, keeps the promise +of compatibility but adds a couple of significant +(backwards-compatible, of course) language changes, has a long list +of (again, compatible) library changes, and +includes major work on the implementation of the compilers, +libraries, and run-time. +The focus is on performance. +Benchmarking is an inexact science at best, but we see significant, +sometimes dramatic speedups for many of our test programs. +We trust that many of our users' programs will also see improvements +just by updating their Go installation and recompiling. +
+ ++This document summarizes the changes between Go 1 and Go 1.1. +Very little if any code will need modification to run with Go 1.1, +although a couple of rare error cases surface with this release +and need to be addressed if they arise. +Details appear below; see the discussion of +64-bit ints and Unicode literals +in particular. +
w
:
func (p []byte) (n int, err error) { - return w.Write(n, err) + return w.Write(p) }@@ -75,7 +107,7 @@ is equivalent to a function with an extra first argument, a receiver of type
func (w *bufio.Writer, p []byte) (n int, err error) { - return w.Write(n, err) + return w.Write(p) }@@ -120,6 +152,17 @@ Such code can be identified by
go vet
.
+The GCC release schedule does not coincide with the Go release schedule, so some skew is inevitable in
+gccgo
's releases.
+The 4.8.0 version of GCC shipped in March, 2013 and includes a nearly-Go 1.1 version of gccgo
.
+Its library is a little behind the release, but the biggest difference is that method values are not implemented.
+Sometime around May 2013, we expect 4.8.1 of GCC to ship with a gccgo
+providing a complete Go 1.1 implementaiton.
+
@@ -169,6 +212,24 @@ would instead say: i := int(int32(x)) +
+On 64-bit architectures only, the maximum heap size has been enlarged substantially, +from a few gigabytes to several tens of gigabytes. +(The exact details depend on the system and may change.) +
+ ++On 32-bit architectures, the heap size has not changed. +
+ ++Updating: +This change should have no effect on existing programs beyond allowing them +to run with larger heaps. +
+@@ -224,6 +285,19 @@ Programs that depend on the old behavior should be modified to avoid the issue. The byte-order-mark change is strictly backward-compatible.
+
+A major addition to the tools is a race detector, a way to find
+bugs in programs caused by problems like concurrent changes to the same variable.
+This new facility is built into the go
tool.
+For now, it is only available on Linux, Mac OS X, and Windows systems with
+64-bit x86 processors.
+To enable it, set the -race
flag when building or testing your program
+(for instance, go test -race
).
+The race detector is documented in a separate article.
+
@@ -277,7 +351,7 @@ when $GOPATH
and $GOROOT
are set to the same value.
$ GOPATH=$GOROOT go get code.google.com/p/foo/quxx -warning: GOPATH set to GOROOT (/home/User/go) has no effect +warning: GOPATH set to GOROOT (/home/you/go) has no effect package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath@@ -320,17 +394,69 @@ To update pre-Go 1 code to Go 1.1, use a Go 1.0 tool chain to convert the code to Go 1.0 first. +
+The go run
command now runs all files in the current working
+directory if no file arguments are listed. Also, the go run
+command now returns an error if test files are provided on the command line. In
+this sense, "go run
" replaces "go run *.go
".
+
+The Go 1.1 tool chain adds experimental support for freebsd/arm
,
+netbsd/386
, netbsd/amd64
, netbsd/arm
,
+openbsd/386
and openbsd/amd64
platforms.
+
+An ARMv6 or later processor is required for freebsd/arm
or
+netbsd/arm
.
+
+Go 1.1 adds experimental support for cgo
on linux/arm
.
+
+When cross-compiling, the go
tool will disable cgo
+support by default.
+
+To explicitly enable cgo
, set CGO_ENABLED=1
.
+
-TODO introduction +The performance of code compiled with the Go 1.1 gc tool suite should be noticeably +better for most Go programs. +Typical improvements relative to Go 1.0 seem to be about 30%-40%, sometimes +much more, but occasionally less or even non-existent. +There are too many small performance-driven tweaks through the tools and libraries +to list them all here, but the following major changes are worth noting:
append
+and interface conversions.
+The data structures
+IPAddr
,
+TCPAddr
, and
+UDPAddr
+add a new string field called Zone
.
+Code using untagged composite literals (e.g. net.TCPAddr{ip, port}
)
+instead of tagged literals (net.TCPAddr{IP: ip, Port: port}
)
+will break due to the new field.
+The Go 1 compatibility rules allow this change: client code must use tagged literals to avoid such breakages.
+
+Updating:
+To correct breakage caused by the new struct field,
+go fix
will rewrite code to add tags for these types.
+More generally, go vet
will identify composite literals that
+should be revised to use field tags.
+
@@ -448,7 +594,7 @@ and
SliceOf
construct new
Types
-from existing types, for example to construct a the type []T
given
+from existing types, for example to construct the type []T
given
only T
.
io.WriterTo
interface.
+compress/gzip
package has
+a new Flush
+method for its
+Writer
+type that flushes its underlying flate.Writer
.
+crypto/hmac
package has a new function,
Equal
, to compare two MACs.
@@ -567,7 +721,7 @@ and a new function
database/sql/
package
+The database/sql
package
has a new
Ping
method for its
@@ -588,7 +742,7 @@ may implement to improve performance.
The encoding/json
package's
Decoder
has a new method
-Reader
+Buffered
to provide access to the remaining data in its buffer,
as well as a new method
UseNumber
@@ -598,7 +752,7 @@ a string, rather than a float64.
endoding/xml
package
+The encoding/xml
package
has a new function,
EscapeText
,
which writes escaped XML output,
@@ -635,12 +789,17 @@ to format arbitrary Go source code.
html/template
package has been removed; programs that depend on it will break.
image/jpeg
package now
+reads progressive JPEG files and handles a few more subsampling configurations.
+io
package now exports the
io.ByteWriter
interface to capture the common
functionality of writing a byte at a time.
net
package's
-net/ListenUnixgram
+ListenUnixgram
function has changed return types: it now returns a
-net/UnixConn
+UnixConn
rather than a
-net/UDPConn
, which was
+UDPConn
, which was
clearly a mistake in Go 1.0.
Since this API change fixes a bug, it is permitted by the Go 1 compatibility rules.
net
package includes a new type,
+Dialer
, to supply options to
+Dial
.
net/http
: ParseTime, CloseNotifier, Request.PostFormValue, ServeMux.Handler, Transport.CancelRequest
+net
package adds support for
+link-local IPv6 addresses with zone qualifiers, such as fe80::1%lo0
.
+The address structures IPAddr
,
+UDPAddr
, and
+TCPAddr
+record the zone in a new field, and functions that expect string forms of these addresses, such as
+Dial
,
+ResolveIPAddr
,
+ResolveUDPAddr
, and
+ResolveTCPAddr
,
+now accept the zone-qualified form.
net/mail
: ParseAddress, ParseAddressList
+net
package adds
+LookupNS
to its suite of resolving functions.
+LookupNS
returns the NS records for a host name.
net/smtp
: Client.Hello
+net
package adds protocol-specific
+packet reading and writing methods to
+IPConn
+(ReadMsgIP
+and WriteMsgIP
) and
+UDPConn
+(ReadMsgUDP
and
+WriteMsgUDP
).
+These are specialized versions of PacketConn
's
+ReadFrom
and WriteTo
methods that provide access to out-of-band data associated
+with the packets.
+ net
package adds methods to
+UnixConn
to allow closing half of the connection
+(CloseRead
and
+CloseWrite
),
+matching the existing methods of TCPConn
.
+net/http
package includes several new additions.
+ParseTime
parses a time string, trying
+several common HTTP time formats.
+The PostFormValue method of
+Request
is like
+FormValue
but ignores URL parameters.
+The CloseNotifier
interface provides a mechanism
+for a server handler to discover when a client has disconnected.
+The ServeMux
type now has a
+Handler
method to access a path's
+Handler
without executing it.
+The Transport
can now cancel an in-flight request with
+CancelRequest
.
+Finally, the Transport is now more aggressive at closing TCP connections when
+a Response.Body
is closed before
+being fully consumed.
+net/http/cookiejar
package provides the basics for managing HTTP cookies.
+net/mail
package has two new functions,
+ParseAddress
and
+ParseAddressList
,
+to parse RFC 5322-formatted mail addresses into
+Address
structures.
+net/smtp
package's
+Client
type has a new method,
+Hello
,
+which transmits a HELO
or EHLO
message to the server.
net
: DialOption, DialOpt, ListenUnixgram, LookupNS, IPConn.ReadMsgIP, IPConn.WriteMsgIP, UDPConn.ReadMsgUDP, UDPConn.WriteMsgUDP, UnixConn.CloseRead, UnixConn.CloseWrite
-os.FileMode.IsRegular
makes it easy to ask if a file is a plain file.
+The new method os.FileMode.IsRegular
makes it easy to ask if a file is a plain file.
image/jpeg
package now
-reads progressive JPEG files and handles a few more subsampling configurations.
+The os/signal
package has a new function,
+Stop
, which stops the package delivering
+any further signals to the channel.
strings
package has two new functio
TrimPrefix
and
TrimSuffix
-with self-evident properties, and the the new method
+with self-evident properties, and the new method
Reader.WriteTo
so the
Reader
type now implements the
@@ -777,8 +1003,11 @@ The syscall
package has received many u
testing
package now automates the generation of allocation
-statistics in benchmarks using the new
-AllocsPerRun
function and the
+statistics in tests and benchmarks using the new
+AllocsPerRun
function. And the
+ReportAllocs
+method on testing.B
will enable printing of
+memory allocation statistics for the calling benchmark. It also introduces the
AllocsPerOp
method of
BenchmarkResult
.
There is also a new
@@ -796,7 +1025,6 @@ In the text/template
and
html/template
packages,
templates can now use parentheses to group the elements of pipelines, simplifying the construction of complex pipelines.
-TODO: Link to example.
Also, as part of the new parser, the
Node
interface got two new methods to provide
better error reporting.
@@ -810,12 +1038,12 @@ packages and there are safeguards to guarantee that.
unicode/utf8
package,
-the new function ValidRune
reports whether the rune is a valid Unicode code point.
-To be valid, a rune must be in range and not be a surrogate half.
+The implementation of the unicode
package has been updated to Unicode version 6.2.0.
unicode
package has been updated to Unicode version 6.2.0.
+In the unicode/utf8
package,
+the new function ValidRune
reports whether the rune is a valid Unicode code point.
+To be valid, a rune must be in range and not be a surrogate half.
+The article Go at Google +discusses the background and motivation behind the design of the Go language, +as well as providing more detail about many of the answers presented in this FAQ. +
+@@ -216,6 +222,13 @@ document server running in a production configuration on Google App Engine.
+
+Other examples include the Vitess
+system for large-scale SQL installations and Google's download server, dl.google.com
,
+which delivers Chrome binaries and other large installables such as apt-get
+packages.
+
pointerMethod
modifies
@@ -1131,7 +1146,7 @@ of Effective Go for more details.
int
32 bits on 64 bit machines?int
on a 64 bit machine?
The sizes of int
and uint
are implementation-specific
@@ -1148,12 +1163,6 @@ floating-point numbers.
The default size of a floating-point constant is float64
.
-At the moment, all implementations use 32-bit ints, an essentially arbitrary decision.
-However, we expect that int
will be increased to 64 bits on 64-bit
-architectures in a future release of Go.
-
Programs that perform parallel computation should benefit from an increase in
GOMAXPROCS
.
+However, be aware that
+concurrency
+is not parallelism.
GOMAXPROCS
should be set on a per-application basis.
++For more detail on this topic see the talk entitled, +Concurrency +is not Parallelism. +
gc
, the original Go compiler, in Go itself bu
elected not to do so because of the difficulties of bootstrapping and
especially of open source distribution—you'd need a Go compiler to
set up a Go environment. Gccgo
, which came later, makes it possible to
-consider writing a compiler in Go, which might well happen. (Go would be a
+consider writing a compiler in Go, which might well happen.
+(Go would be a
fine language in which to implement a compiler; a native lexer and
-parser are already available in the go
package.)
+parser are already available in the go
package
+and a type checker is in the works.)
diff --git a/doc/go_spec.html b/doc/go_spec.html index 881d16656..214d1c0ac 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -837,9 +837,9 @@ multi-dimensional types.
-A slice is a reference to a contiguous segment of an array and
-contains a numbered sequence of elements from that array. A slice
-type denotes the set of all slices of arrays of its element type.
+A slice is a descriptor for a contiguous segment of an array and
+provides access to a numbered sequence of elements from that array.
+A slice type denotes the set of all slices of arrays of its element type.
The value of an uninitialized slice is nil
.
-Slices, maps and channels are reference types that do not require the
-extra indirection of an allocation with new
.
The built-in function make
takes a type T
,
which must be a slice, map or channel type,
optionally followed by a type-specific list of expressions.
diff --git a/doc/godocs.js b/doc/godocs.js
index 5d12da131..6875f74d8 100644
--- a/doc/godocs.js
+++ b/doc/godocs.js
@@ -179,6 +179,13 @@ function fixFocus() {
}).resize();
}
+function toggleHash() {
+ var hash = $(window.location.hash);
+ if (hash.is('.toggle')) {
+ hash.addClass('toggleVisible').removeClass('toggle');
+ }
+}
+
$(document).ready(function() {
bindSearchEvents();
generateTOC();
@@ -190,6 +197,7 @@ $(document).ready(function() {
bindToggleLinks(".indexLink", "");
setupDropdownPlayground();
fixFocus();
+ toggleHash();
});
})();
diff --git a/doc/install.html b/doc/install.html
index 03b13c018..f2e21b441 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -3,25 +3,34 @@
"Path": "/doc/install"
}-->
-
-Go is an open source project with a BSD-style license.
-There are two official Go compiler toolchains: the gc
Go compiler
-and the gccgo
compiler that is part of the GNU C Compiler (GCC).
+
+Download Go
+Click here to visit the downloads page
+
-The gc
compiler is the more mature and well-tested of the two.
-This page is about installing a binary distribution of the gc
-compiler.
+Click the link above to visit the
+Go project's downloads page
+and select the binary distribution that matches your operating system and
+processor architecture.
-For information about installing the gc
compiler from source, see
-Installing Go from source.
-For information about installing gccgo
, see
-Setting up and using gccgo.
+Official binary distributions are available for the FreeBSD, Linux, Mac OS X
+(Snow Leopard, Lion, and Mountain Lion), NetBSD, and Windows operating systems
+and the 32-bit (386
) and 64-bit (amd64
) x86 processor
+architectures.
+
+If a binary distribution is not available for your combination of operating +system and architecture you may want to try +installing from source or +installing gccgo instead of gc.
-Visit the -Go project's downloads page -and select the binary distribution that matches -your operating system and processor architecture. -
- -
-Official binary distributions are available
-for the FreeBSD, Linux, Mac OS X (Snow Leopard/Lion), NetBSD, and Windows operating systems
-and the 32-bit (386
) and 64-bit (amd64
)
-x86 processor architectures.
-
-If a binary distribution is not available for your -OS/arch combination you may want to try -installing from source or -installing gccgo instead of gc. -
-diff --git a/doc/style.css b/doc/style.css index 3d881b03a..5c8e17a29 100644 --- a/doc/style.css +++ b/doc/style.css @@ -12,7 +12,7 @@ pre { line-height: 18px; } pre .comment { - color: #375EAB; + color: #006600; } pre .highlight, pre .highlight-comment, @@ -198,6 +198,9 @@ div#blog .read a { border: 1px solid #375EAB; background: #E0EBF5; } +.download { + width: 150px; +} div#menu { float: right; diff --git a/include/libc.h b/include/libc.h index fab1532f2..e10dde3ad 100644 --- a/include/libc.h +++ b/include/libc.h @@ -291,6 +291,7 @@ extern char* getgoroot(void); extern char* getgoversion(void); extern char* getgoarm(void); extern char* getgo386(void); +extern char* getgoextlinkenabled(void); extern char* mktempdir(void); extern void removeall(char*); diff --git a/include/plan9/libc.h b/include/plan9/libc.h index e6f9839c8..dcecc7c8b 100644 --- a/include/plan9/libc.h +++ b/include/plan9/libc.h @@ -18,6 +18,7 @@ char* getgoroot(void); char* getgoversion(void); char* getgoarm(void); char* getgo386(void); +char* getgoextlinkenabled(void); void flagcount(char*, char*, int*); void flagint32(char*, char*, int32*); diff --git a/lib/codereview/codereview.py b/lib/codereview/codereview.py index 11766fcb2..f839263c5 100644 --- a/lib/codereview/codereview.py +++ b/lib/codereview/codereview.py @@ -1762,7 +1762,8 @@ def gofmt(ui, repo, *pats, **opts): files = ChangedExistingFiles(ui, repo, pats, opts) files = gofmt_required(files) if not files: - return "no modified go files" + ui.status("no modified go files\n") + return cwd = os.getcwd() files = [RelativePath(repo.root + '/' + f, cwd) for f in files] try: diff --git a/lib/godoc/package.html b/lib/godoc/package.html index 33c2c2791..aefbef9fd 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -40,7 +40,7 @@ {{comment_html .Doc}} - {{example_html "" $.Examples $.FSet}} + {{example_html $ ""}}
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{end}} {{end}} {{with .Vars}}
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{end}} {{end}} {{range .Funcs}} {{/* Name is a string - no need for FSet */}} {{$name_html := html .Name}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} - {{example_html .Name $.Examples $.FSet}} + {{example_html $ .Name}} {{end}} {{range .Types}} {{$tname := .Name}} {{$tname_html := html .Name}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{range .Consts}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{end}} {{range .Vars}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{end}} - {{example_html $tname $.Examples $.FSet}} + {{example_html $ $tname}} {{range .Funcs}} {{$name_html := html .Name}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} - {{example_html .Name $.Examples $.FSet}} + {{example_html $ .Name}} {{end}} {{range .Methods}} {{$name_html := html .Name}} -
{{node_html .Decl $.FSet}}+
{{node_html $ .Decl true}}{{comment_html .Doc}} {{$name := printf "%s_%s" $tname .Name}} - {{example_html $name $.Examples $.FSet}} + {{example_html $ $name}} {{end}} {{end}} {{end}} @@ -169,9 +169,9 @@ {{with $.Notes}} {{range $marker, $content := .}}
{{node_html . $.FSet}}+
{{node_html $ . false}}{{end}} {{with .Dirs}} diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt index bc11fc3c5..d191621c0 100644 --- a/lib/godoc/package.txt +++ b/lib/godoc/package.txt @@ -1,4 +1,4 @@ -{{with .PAst}}{{node . $.FSet}}{{end}}{{/* +{{with .PAst}}{{node $ .}}{{end}}{{/* --------------------------------------- @@ -11,55 +11,54 @@ package {{.Name}} import "{{.ImportPath}}" {{comment_text .Doc " " "\t"}} -{{example_text "" $.Examples $.FSet " "}}{{/* +{{example_text $ "" " "}}{{/* --------------------------------------- */}}{{with .Consts}} CONSTANTS -{{range .}}{{node .Decl $.FSet}} -{{comment_text .Doc " " "\t"}}{{end}} -{{end}}{{/* +{{range .}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{end}}{{/* --------------------------------------- */}}{{with .Vars}} VARIABLES -{{range .}}{{node .Decl $.FSet}} -{{comment_text .Doc " " "\t"}}{{end}} -{{end}}{{/* +{{range .}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{end}}{{/* --------------------------------------- */}}{{with .Funcs}} FUNCTIONS -{{range .}}{{node .Decl $.FSet}} +{{range .}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{example_text .Name $.Examples $.FSet " "}} -{{end}}{{end}}{{/* +{{example_text $ .Name " "}}{{end}}{{end}}{{/* --------------------------------------- */}}{{with .Types}} TYPES -{{range .}}{{$tname := .Name}}{{node .Decl $.FSet}} +{{range .}}{{$tname := .Name}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{range .Consts}}{{node .Decl $.FSet}} +{{range .Consts}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{end}}{{range .Vars}}{{node .Decl $.FSet}} +{{end}}{{range .Vars}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{end}}{{example_text .Name $.Examples $.FSet " "}} -{{range .Funcs}}{{node .Decl $.FSet}} +{{end}}{{example_text $ .Name " "}} +{{range .Funcs}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{example_text .Name $.Examples $.FSet " "}} -{{end}}{{range .Methods}}{{node .Decl $.FSet}} +{{example_text $ .Name " "}} +{{end}}{{range .Methods}}{{node $ .Decl}} {{comment_text .Doc " " "\t"}} -{{$name := printf "%s_%s" $tname .Name}}{{example_text $name $.Examples $.FSet " "}} -{{end}}{{end}}{{end}}{{end}}{{/* +{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}} +{{end}}{{end}}{{end}}{{/* --------------------------------------- diff --git a/lib/time/update.bash b/lib/time/update.bash index ef7fdc79b..c2377e124 100755 --- a/lib/time/update.bash +++ b/lib/time/update.bash @@ -7,8 +7,8 @@ # downloaded from the ICANN/IANA distribution. # Versions to use. -CODE=2011i -DATA=2011n +CODE=2013b +DATA=2013b set -e rm -rf work diff --git a/lib/time/zoneinfo.zip b/lib/time/zoneinfo.zip index b54213239..c10a42576 100644 Binary files a/lib/time/zoneinfo.zip and b/lib/time/zoneinfo.zip differ diff --git a/misc/cgo/gmp/gmp.go b/misc/cgo/gmp/gmp.go index 3bcf99151..7b7a9b3c9 100644 --- a/misc/cgo/gmp/gmp.go +++ b/misc/cgo/gmp/gmp.go @@ -33,7 +33,7 @@ field; unrepresentable fields are replaced with opaque byte arrays. A C union translates into a struct containing the first union member and perhaps additional padding. C arrays become Go arrays. C pointers become Go pointers. C function pointers become Go's uintptr. -C void pointer's become Go's unsafe.Pointer. +C void pointers become Go's unsafe.Pointer. For example, mpz_t is defined in