New import paths for Go sub-respositories

3018 views
Skip to first unread message

Andrew Gerrand

unread,
Nov 5, 2014, 4:50:07 PM11/5/14
to golang-nuts
Summary: The sub-repo import paths are changing from "code.google.com/p/go.*" to "golang.org/x/*". Please update your code on or before November 9.

As a prelude to the Go 1.4 release, the Go sub-repositories (go.tools, go.net, go.crypto, and so on) will be made available using custom import paths. See golang.org/s/go14subrepo for background.

This list shows the current base import paths, and their new equivalents.


The "x" in the path serves to disambiguate these external packages from the standard library.

If your code imports packages from these repositories, please prepare changes to update the import paths, and commit those changes either before or shortly after the official repositories are renamed. (These new import paths work today, but the code in those repositories has not yet been updated to use them.)

The change will be made on Sunday, November 9, 2014.

Updating

Any import path in any Go source file beginning with “code.google.com/p/go.” should change to begin with “golang.org/x/”.

On Linux, OS X, and other Unix systems, this command updates all Go source files in the current directory and all subdirectories, so running it in your GOPATH workspace root should suffice to update all your source code:

    sed -i .orig 's|"code\.google\.com/p/go\.|"golang.org/x/|' \
        $(find . -name '*.go')

Potential issues

After the change, code that uses the old import paths will not break. Instead, two copies of a given repository may be created inside your workspace.

For example, the "code.google.com/p/go.tools/go/ssa" package depends on "code.google.com/p/go.tools/go/types". After the change, these two paths will become "golang.org/x/tools/go/ssa" and "golang.org/x/tools/go/types", and the import statement in package ssa will be updated accordingly.

If your code imports the ssa package using its old path, when the import paths are changed the dependency graph will look like this:


If you run "go get", it will check out two copies of the go.tools repository: one under the old path, and one under the new path. If your program also contains references to "code.google.com/p/go.tools/go/types", you will end up with both copies of the go/types package (with different import paths) in the same executable.

To fix this, update the import statements in your code to use the new paths and then delete the old "src/code.google.com/p/go.*" directories from your workspace.


Andrew Gerrand

unread,
Nov 10, 2014, 1:38:27 AM11/10/14
to golang-nuts
The change has been made; the new paths are in effect.

Please update your code as per the instructions below, if you haven't done so already.
Reply all
Reply to author
Forward
0 new messages