Introduction to Go 1

For a full explanation of the motivation and design of Go 1, see XXX. Here follows a summary.

Go 1 is intended to be a stable language and core library set that will form a reliable foundation for people and organizations that want to make a long-term commitment to developing in the Go programming language. Go will continue to develop, but in a way that guarantees code written to the Go 1 specification will continue to work. For instance, Go 1 will be a supported platform on Google App Engine for the next few years. Incompatible changes to the environment, should they arise, will be done in a distinct version.

This document describes the changes in the language and libraries in Go 1, relative to the previous release, r60 (at the time of writing, tagged as r60.3). It also explains how to update code at r60 to compile and run under Go 1. Finally, it outlines the new go command for building Go programs and the new binary release process being introduced. Most of these topics have more thorough presentations elsewhere; such documents are linked below.

Changes to the language

Append

Close

Composite literals

Goroutines during init

The rune type

Deleting from maps

The original syntax for deleting an element in a map was:

    m[x] = ignored, false

In Go 1, that syntax has gone; instead there is a new built-in function, delete. The call

    delete(m, k)

will delete the map entry retrieved by the expression m[k]. There is no return value. Deleting a non-existent entry is a no-op.

Updating: Gofix will convert expressions of the form m[k] = ignored, false into delete(m, k) when it is clear that the ignored value can be safely discarded from the program and false refers to the predefined boolean constant. Gofix will flag other uses of the syntax for inspection by the programmer.

Iterating in maps

Multiple assignment

Returns and shadowed variables

Equality of structs and arrays

Changes to the library

The package hierarchy

Go 1 has a rearranged package hierarchy that groups related items into subdirectories. For instance, utf8 and utf16 now occupy subdirectories of unicode. Also, some packages have moved into subrepositories of code.google.com/p/go while others have been deleted outright.

Old path New path
asn1 encoding/asn1
csv encoding/csv
gob encoding/gob
json encoding/json
xml encoding/xml

exp/template/html html/template

big math/big
cmath math/cmplx
rand math/rand

http net/http
http/cgi net/http/cgi
http/fcgi net/http/fcgi
http/httptest net/http/httptest
http/pprof net/http/pprof
mail net/mail
rpc net/rpc
rpc/jsonrpc net/rpc/jsonrpc
smtp net/smtp
url net/url

exec os/exec

scanner text/scanner
tabwriter text/tabwriter
template text/template
template/parse text/template/parse

utf8 unicode/utf8
utf16 unicode/utf16

Note that the package names for the old cmath and exp/template/html packages have changed to cmplx and template.

Updating: Gofix will update all imports and package renames for packages that remain inside the standard repository. Programs that import packages that are no longer in the standard repository will need to be edited by hand. TODO: should warn about deletions. TODO: should also handle packages that move to subrepos.

The error type

System call errors

Time

The html package

The http package

The strconv package

The package tree exp

The package tree old

Deleted packages

Packages moving to subrepositories

The os.FileInfo type

The go command

Packaged releases