Skip to content

Commit

Permalink
all: use golang.org/x/... import paths
Browse files Browse the repository at this point in the history
LGTM=rsc, r
R=r, rsc
CC=golang-codereview, golang-codereviews
https://golang.org/cl/168050043
  • Loading branch information
adg committed Nov 9, 2014
1 parent 68e2dbe commit 7f0be1f
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 122 deletions.
13 changes: 7 additions & 6 deletions doc/articles/go_command.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ <h2>Go's conventions</h2>
source code. For Bitbucket, GitHub, Google Code, and Launchpad, the
root directory of the repository is identified by the repository's
main URL, without the <code>http://</code> prefix. Subdirectories are named by
adding to that path. For example, the supplemental networking
libraries for Go are obtained by running</p>
adding to that path.
For example, the Go example programs are obtained by running</p>

<pre>
hg clone http://code.google.com/p/go.net
git clone https://github.com/golang/example
</pre>

<p>and thus the import path for the root directory of that repository is
"<code>code.google.com/p/go.net</code>". The websocket package is stored in a
subdirectory, so its import path is
"<code>code.google.com/p/go.net/websocket</code>".</p>
"<code>github.com/golang/example</code>".
The <a href="https://godoc.org/github.com/golang/example/stringutil">stringutil</a>
package is stored in a subdirectory, so its import path is
"<code>github.com/golang/example/stringutil</code>".</p>

<p>These paths are on the long side, but in exchange we get an
automatically managed name space for import paths and the ability for
Expand Down
6 changes: 3 additions & 3 deletions doc/cmd.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</tr>

<tr>
<td><a href="//godoc.org/code.google.com/p/go.tools/cmd/cover/">cover</a></td>
<td><a href="//godoc.org/golang.org/x/tools/cmd/cover/">cover</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Cover is a program for creating and analyzing the coverage profiles
generated by <code>"go test -coverprofile"</code>.</td>
Expand All @@ -83,13 +83,13 @@
</tr>

<tr>
<td><a href="//godoc.org/code.google.com/p/go.tools/cmd/godoc/">godoc</a></td>
<td><a href="//godoc.org/golang.org/x/tools/cmd/godoc/">godoc</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Godoc extracts and generates documentation for Go packages.</td>
</tr>

<tr>
<td><a href="//godoc.org/code.google.com/p/go.tools/cmd/vet/">vet</a></td>
<td><a href="//godoc.org/golang.org/x/tools/cmd/vet/">vet</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>Vet examines Go source code and reports suspicious constructs, such as Printf
calls whose arguments do not align with the format string.</td>
Expand Down
183 changes: 96 additions & 87 deletions doc/code.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,35 @@ <h3 id="Workspaces">Workspaces</h3>

<pre>
bin/
streak # command executable
todo # command executable
hello # command executable
outyet # command executable
pkg/
linux_amd64/
code.google.com/p/goauth2/
oauth.a # package object
github.com/nf/todo/
task.a # package object
github.com/golang/example/
stringutil.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
<a href="https://github.com/golang/example/">github.com/golang/example/</a>
.git/ # Git repository metadata
hello/
hello.go # command source
outyet/
main.go # command source
main_test.go # test source
stringutil/
reverse.go # package source
reverse_test.go # test source
</pre>

<p>
This workspace contains three repositories (<code>goauth2</code>,
<code>streak</code>, and <code>todo</code>) comprising two commands
(<code>streak</code> and <code>todo</code>) and two libraries
(<code>oauth</code> and <code>task</code>).
This workspace contains one repository (<code>example</code>)
comprising two commands (<code>hello</code> and <code>outyet</code>)
and one library (<code>stringutil</code>).
</p>

<p>
A typical workspace would contain many source repositories containing many
packages and commands. Most Go programmers keep <i>all</i> their Go source code
and dependencies in a single workspace.
</p>

<p>
Expand Down Expand Up @@ -277,29 +275,29 @@ <h3 id="Library">Your first library</h3>

<p>
Again, the first step is to choose a package path (we'll use
<code>github.com/user/newmath</code>) and create the package directory:
<code>github.com/user/stringutil</code>) and create the package directory:
</p>

<pre>
$ <b>mkdir $GOPATH/src/github.com/user/newmath</b>
$ <b>mkdir $GOPATH/src/github.com/user/stringutil</b>
</pre>

<p>
Next, create a file named <code>sqrt.go</code> in that directory with the
Next, create a file named <code>reverse.go</code> in that directory with the
following contents.
</p>

<pre>
// Package newmath is a trivial example package.
package newmath

// Sqrt returns an approximation to the square root of x.
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; i &lt; 1000; i++ {
z -= (z*z - x) / (2 * z)
// Package stringutil contains utility functions for working with strings.
package stringutil

// Reverse returns its argument string reversed rune-wise left to right.
func Reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i &lt; len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return z
return string(r)
}
</pre>

Expand All @@ -308,7 +306,7 @@ <h3 id="Library">Your first library</h3>
</p>

<pre>
$ <b>go build github.com/user/newmath</b>
$ <b>go build github.com/user/stringutil</b>
</pre>

<p>
Expand All @@ -326,7 +324,7 @@ <h3 id="Library">Your first library</h3>
</p>

<p>
After confirming that the <code>newmath</code> package builds,
After confirming that the <code>stringutil</code> package builds,
modify your original <code>hello.go</code> (which is in
<code>$GOPATH/src/github.com/user/hello</code>) to use it:
</p>
Expand All @@ -337,35 +335,35 @@ <h3 id="Library">Your first library</h3>
import (
"fmt"

<b>"github.com/user/newmath"</b>
<b>"github.com/user/stringutil"</b>
)

func main() {
fmt.Printf("Hello, world. <b>Sqrt(2) = %v\n", newmath.Sqrt(2)</b>)
fmt.Printf(stringutil.Reverse("!oG ,olleH"))
}
</pre>

<p>
Whenever the <code>go</code> tool installs a package or binary, it also
installs whatever dependencies it has. So when you install the <code>hello</code>
program
installs whatever dependencies it has.
So when you install the <code>hello</code> program
</p>

<pre>
$ <b>go install github.com/user/hello</b>
</pre>

<p>
the <code>newmath</code> package will be installed as well, automatically.
the <code>stringutil</code> package will be installed as well, automatically.
</p>

<p>
Running the new version of the program, you should see some numerical output:
Running the new version of the program, you should see a new, reversed message:
</p>

<pre>
$ <b>hello</b>
Hello, world. Sqrt(2) = 1.414213562373095
Hello, Go!
</pre>

<p>
Expand All @@ -374,22 +372,22 @@ <h3 id="Library">Your first library</h3>

<pre>
bin/
hello # command executable
hello # command executable
pkg/
linux_amd64/ # this will reflect your OS and architecture
linux_amd64/ # this will reflect your OS and architecture
github.com/user/
newmath.a # package object
stringutil.a # package object
src/
github.com/user/
hello/
hello.go # command source
newmath/
sqrt.go # package source
hello.go # command source
stringutil/
reverse.go # package source
</pre>

<p>
Note that <code>go install</code> placed the <code>newmath.a</code> object in a
directory inside <code>pkg/linux_amd64</code> that mirrors its source
Note that <code>go install</code> placed the <code>stringutil.a</code> object
in a directory inside <code>pkg/linux_amd64</code> that mirrors its source
directory.
This is so that future invocations of the <code>go</code> tool can find the
package object and avoid recompiling the package unnecessarily.
Expand Down Expand Up @@ -457,20 +455,29 @@ <h2 id="Testing">Testing</h2>
</p>

<p>
Add a test to the <code>newmath</code> package by creating the file
<code>$GOPATH/src/github.com/user/newmath/sqrt_test.go</code> containing the
following Go code.
Add a test to the <code>stringutil</code> package by creating the file
<code>$GOPATH/src/github.com/user/stringutil/reverse_test.go</code> containing
the following Go code.
</p>

<pre>
package newmath
package stringutil

import "testing"

func TestSqrt(t *testing.T) {
const in, out = 4, 2
if x := Sqrt(in); x != out {
t.Errorf("Sqrt(%v) = %v, want %v", in, x, out)
func TestReverse(t *testing.T) {
cases := []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
}
for _, c := range cases {
got := Reverse(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}
}
</pre>
Expand All @@ -480,8 +487,8 @@ <h2 id="Testing">Testing</h2>
</p>

<pre>
$ <b>go test github.com/user/newmath</b>
ok github.com/user/newmath 0.165s
$ <b>go test github.com/user/stringutil</b>
ok github.com/user/stringutil 0.165s
</pre>

<p>
Expand All @@ -491,7 +498,7 @@ <h2 id="Testing">Testing</h2>

<pre>
$ <b>go test</b>
ok github.com/user/newmath 0.165s
ok github.com/user/stringutil 0.165s
</pre>

<p>
Expand All @@ -507,16 +514,16 @@ <h2 id="remote">Remote packages</h2>
revision control system such as Git or Mercurial. The <code>go</code> 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,
<code><a href="//code.google.com/p/go.example">code.google.com/p/go.example</a></code>.
Git repository hosted at GitHub
<code><a href="https://github.com/golang/example">github.com/golang/example</a></code>.
If you include the repository URL in the package's import path,
<code>go get</code> will fetch, build, and install it automatically:
</p>

<pre>
$ <b>go get code.google.com/p/go.example/hello</b>
$ <b>go get github.com/golang/example/hello</b>
$ <b>$GOPATH/bin/hello</b>
Hello, world. Sqrt(2) = 1.414213562373095
Hello, Go examples!
</pre>

<p>
Expand All @@ -533,37 +540,39 @@ <h2 id="remote">Remote packages</h2>

<pre>
bin/
hello # command executable
hello # command executable
pkg/
linux_amd64/
code.google.com/p/go.example/
newmath.a # package object
github.com/golang/example/
stringutil.a # package object
github.com/user/
newmath.a # package object
stringutil.a # package object
src/
code.google.com/p/go.example/
github.com/golang/example/
.git/ # Git repository metadata
hello/
hello.go # command source
newmath/
sqrt.go # package source
sqrt_test.go # test source
hello.go # command source
stringutil/
reverse.go # package source
reverse_test.go # test source
github.com/user/
hello/
hello.go # command source
newmath/
sqrt.go # package source
sqrt_test.go # test source
hello.go # command source
stringutil/
reverse.go # package source
reverse_test.go # test source
</pre>

<p>
The <code>hello</code> command hosted at Google Code depends on the
<code>newmath</code> package within the same repository. The imports in
<code>hello.go</code> file use the same import path convention, so the <code>go
get</code> command is able to locate and install the dependent package, too.
The <code>hello</code> command hosted at GitHub depends on the
<code>stringutil</code> package within the same repository. The imports in
<code>hello.go</code> file use the same import path convention, so the
<code>go get</code> command is able to locate and install the dependent
package, too.
</p>

<pre>
import "code.google.com/p/go.example/newmath"
import "github.com/golang/example/stringutil"
</pre>

<p>
Expand Down
2 changes: 1 addition & 1 deletion doc/contribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3>Configure the extension</h3>

<p>To contribute to subrepositories, edit the <code>.hg/hgrc</code> for each
subrepository in the same way. For example, add the codereview extension to
<code>code.google.com/p/go.tools/.hg/hgrc</code>.
<code>golang.org/x/tools/.hg/hgrc</code>.
</p>

<h3>Understanding the extension</h3>
Expand Down
Loading

0 comments on commit 7f0be1f

Please sign in to comment.