[Translate] from R60 to go 1

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go1 release of the day more and more close, the Golang community like the spring water will be opened, the parking is constantly coming from all kinds of voices about Go1.
This article is summarized in a more complete, clear, and then translated.
Original: http://gophersays.com/from-r60-to-go1/

—————-Translation Split Line —————-

Go 1 has come to the door, guys, it has many changes!

Here are some important things you need to know:

Go command
New map Delete Syntax
Error has its own bag.
Overridden libraries
The new library

Go command

Go has a new main command, go, to replace all the other old go commands:

previous now
godoc Go doc
gofix go fix
gofmt-l-w *.go go fmt
goinstall go get
gorun go run
gotest go test
govet go vet
make go build
make clean go clean
make install Go install

(Most of the tool commands, including 6g/8g, 6l/8l, 6cov/8cov, Gotype, Gopprof, and 6prof/8prof, are now the Go tool.) See the Go tool to see the full list. )

Come on, makefiles.

Go 1 has abandoned makefiles, which is always a temporary solution anyway. As an alternative, all things-including how to get packages, how to compile them, and how to test them-will be exported directly from the source code, all of which are controlled by an environment variable, Gopath.

In order for Go 1 to compile a package, the package must be included in the path list of the Gopath. (If Gopath is not set, go uses its own directory instead.) )

    • All compiled binary Wenjian (thx Joe Yougy) files are stored in Gopath/bin
    • All compiled packages are stored in gopath/pkg//
    • All source code stored in gopath/src/

This means that if there is a package Github.com/pmylund/helloworld, the source code should be saved in the directory Src/github.com/pmylund/helloworld listed in Gopath. When you execute go install, the compiled package will appear in the Pkg//github.com/pmylund/helloworld in this Gopath directory.

Because of these new conventions, the only configuration that Go needs is gopath. There are no Makefile, no custom scripts, and no need to worry about naming conflicts.

Here's an example of building and executing your own projects, and avoiding the clutter of your project's catalog with external code. (e.g. using go get):

In ~/.bash_aliases (or ~/.BASH_RC):

mygo=/home/patrick/projects/gogoroot=/home/patrick/apps/gogobin= $goroot/bin: $mygo/binexport GOPATH= $goroot: $ Mygoexport path= $PATH: $gobin

Because the Go directory is the first folder listed in Gopath, this will be used as the default target directory for use with the go get command--unless your project has been reset to another directory, this will be the place to store your project's compiled bin and pkg directories.

(If you don't have write access to the Go directory, you can specify another as the default directory instead of Goroot.) Go will install all the new third-party packages there. )

(When you build a project that will import a package, for example, Github.com/pmylund/helloworld,go will look in all the directories listed in Gopath.) )

To understand the rationale behind this, refer to Russ Cox's message called the Go Command published on the golang-nuts mailing list.

New map Delete Syntax

You can now use Delete (map, "key") instead of map["key" = nil, false.

Error has its own bag.

Error moved from OS to errors. Again, error is now a built-in type, so you can use it without importing anything.

before now
os.Error error
os.NewError(text string) os.Error errors.New(text string) error
err.String() string err.Error() string

The reconstructed library

The following table lists the import paths for the old and new packages. (All these can be fixed automatically with Go fix.) )

Overridden libraries

Package Change
strconv Obvious refactoring
template Replace with a new API text/template
time Completely redesigned
url Moved to net/url and made a number of changes, most notably url.URL in the URL.Raw removed, and should be used URL.String() as a substitute for

The new library

Package Description
database/sql Standard interface for manipulating relational databases (already existing drivers are SQLite, MySQL, PostgreSQL, etc.)
html/template text/templateOne of the Xss-safe packages

This does not cover all of the language and package changes in Go 1. See the Go 1 release notes (still in progress) and weekly snapshot history for more information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.