MMS • RSS
Article originally posted on InfoQ. Visit InfoQ
The two main features of Go 1.11 are WebAssembly and modules, although both still in experimental stage.
Modules provide an alternative to
GOPATH to locate dependencies for a project and to manage versioning. If the
go command is run outside of
$GOPATH/src in a directory where a module is present, then modules are enabled, otherwise
go will use
GOPATH. As Google Russ Cox explains:
A Go module is a collection of packages sharing a common import path prefix, known as the module path. The module is the unit of versioning, and module versions are written as semantic version strings. When developing using Git, developers will define a new semantic version of a module by adding a tag to the module’s Git repository. Although semantic versions are strongly preferred, referring to specific commits will be supported as well.
A module is created using
go mod and is defined by a
go.mod file in the module root which lists all required packages with their version numbers. For example, this is a simple module definition file declaring the module’s base directory and two dependencies that is created running
go mod -init -module example.com/m:
module example.com/m require ( golang.org/x/text v0.3.0 gopkg.in/yaml.v2 v2.1.0 )
go.mod file exists, commands like
go test, or
go list will automatically add new dependencies to satisfy imports. For example, importing
rsc.io/quote in your main package, then executing
go run would add
require rsc.io/quote v1.5.2 to
go.mod. Similarly, the
go get command updates
go.mod to change the module versions used in a build and may upgrade or downgrade any recursive dependencies.
More details on modules syntax can be found running
go help modules. The feature will remain in experimental stage at least until Go 1.12 and the Go team will strive to preserve compatibility. Once modules are stable, support for working with GOPATH will be removed.
Support for WebAssembly aims to make it possible to run Go programs inside of Web browsers. You can compile a Go program for the Web running:
GOARCH=wasm GOOS=js go build -o test.wasm main.go. This will produce three files,
test.wasm, that you can deploy to your HTTP server or load directly into a browser. The
js package can be used for DOM manipulation.
For full list of all changes in Go 1.11, do not miss the official release notes. You can find here a list of all available downloads.