From 2b7946d3f752402d413768082184f2f3217aaef4 Mon Sep 17 00:00:00 2001 From: HadesHappy Date: Tue, 6 Apr 2021 09:43:53 -0400 Subject: [PATCH] README.md: update package paths to be golang.org/x/example/... The module name is golang.org/x/example and the canonical repo is go.googlesource.com/example. Add the pkg.go.dev link in the main README.md and remove stale godoc.org links. Change-Id: Ia67be2179885d144c97284237df1f4373717722d Reviewed-on: https://go-review.googlesource.com/c/example/+/307689 Trust: Hyang-Ah Hana Kim Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Go Bot Reviewed-by: Suzy Mueller --- README.md | 21 +++++++++++---------- gotypes/README.md | 40 ++++++++++++++++++++-------------------- gotypes/weave.go | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 28c5e94..72072d6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # Go example projects + +[![Go Reference](https://pkg.go.dev/badge/golang.org/x/example.svg)](https://pkg.go.dev/golang.org/x/example) + This repository contains a collection of Go programs and libraries that demonstrate the language, standard libraries, and tools. -## The examples - -### [hello](hello/) ([godoc](//godoc.org/github.com/golang/example/hello)) and [stringutil](stringutil/) ([godoc](//godoc.org/github.com/golang/example/stringutil)) +## [hello](hello/) and [stringutil](stringutil/) - go get github.com/golang/example/hello + go get golang.org/x/example/hello A trivial "Hello, world" program that uses a stringutil package. @@ -23,9 +24,9 @@ Library [stringutil](stringutil/) covers: * Conversion between string and []rune * Table-driven unit tests ([testing](//golang.org/pkg/testing/)) -### [outyet](outyet/) ([godoc](//godoc.org/github.com/golang/example/outyet)) +## [outyet](outyet/) - go get github.com/golang/example/outyet + go get golang.org/x/example/outyet A web server that answers the question: "Is Go 1.x out yet?" @@ -42,16 +43,16 @@ Topics covered: * Dependency injection * Time ([time](//golang.org/pkg/time/)) -### [appengine-hello](appengine-hello/) ([godoc](//godoc.org/github.com/golang/example/appengine-hello)) +## [appengine-hello](appengine-hello/) - goapp get github.com/golang/example/appengine-hello + goapp get golang.org/x/example/appengine-hello A trivial "Hello, world" App Engine application intended to be used as the starting point for your own code. _Note_: The `goapp` tool is part of the [Google App Engine SDK for Go](https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go). -### [gotypes](gotypes/) ([godoc](//godoc.org/github.com/golang/example/gotypes)) +## [gotypes](gotypes/) The `go/types` package is a type-checker for Go programs. It is one of the most complex packages in Go's standard library, so we have provided this tutorial to @@ -59,7 +60,7 @@ help you find your bearings. It comes with several example programs that you can obtain using `go get` and play with as you learn to build tools that analyze or manipulate Go programs. -### [template](template/) ([godoc](//godoc.org/github.com/golang/example/template)) +## [template](template/) A trivial web server that demonstrates the use of the [`template` package](https://golang.org/pkg/text/template/)'s `block` feature. diff --git a/gotypes/README.md b/gotypes/README.md index a235fc8..e6883f5 100644 --- a/gotypes/README.md +++ b/gotypes/README.md @@ -78,7 +78,7 @@ constant expressions, as we'll see in -The [`golang.org/x/tools/go/loader` package](https://godoc.org/golang.org/x/tools/go/loader) +The [`golang.org/x/tools/go/loader` package](https://pkg.go.dev/golang.org/x/tools/go/loader) from the `x/tools` repository is a client of the type checker that loads, parses, and type-checks a complete Go program from source code. @@ -133,10 +133,10 @@ the _hello, world_ program, supplied as a string. Later examples will be variations on this one, and we'll often omit boilerplate details such as parsing. To check out and build the examples, -run `go get github.com/golang/example/gotypes/...`. +run `go get golang.org/x/example/gotypes/...`. - // go get github.com/golang/example/gotypes/pkginfo + // go get golang.org/x/example/gotypes/pkginfo ``` package main @@ -243,7 +243,7 @@ Finally, the program prints the attributes of the package, shown below. ``` -$ go build github.com/golang/example/gotypes/pkginfo +$ go build golang.org/x/example/gotypes/pkginfo $ ./pkginfo Package "cmd/hello" Name: main @@ -492,7 +492,7 @@ The function below prints the location of each referring and defining identifier in the input program, and the object it refers to. - // go get github.com/golang/example/gotypes/defsuses + // go get golang.org/x/example/gotypes/defsuses ``` func PrintDefsUses(fset *token.FileSet, files ...*ast.File) error { @@ -522,7 +522,7 @@ func PrintDefsUses(fset *token.FileSet, files ...*ast.File) error { Let's use the _hello, world_ program again as the input: - // go get github.com/golang/example/gotypes/hello + // go get golang.org/x/example/gotypes/hello ``` package main @@ -539,7 +539,7 @@ This is what it prints: ``` -$ go build github.com/golang/example/gotypes/defsuses +$ go build golang.org/x/example/gotypes/defsuses $ ./defsuses hello.go:1:9: "main" defines hello.go:5:6: "main" defines func hello.main() @@ -783,7 +783,7 @@ Observe that the `ParseComments` flag directs the parser to preserve comments in the input. - // go get github.com/golang/example/gotypes/lookup + // go get golang.org/x/example/gotypes/lookup ``` func main() { @@ -853,7 +853,7 @@ Here's the output: ``` -$ go build github.com/golang/example/gotypes/lookup +$ go build golang.org/x/example/gotypes/lookup $ ./lookup At hello.go:6:1, "append" = builtin append At hello.go:8:9, "fmt" = package fmt @@ -1467,7 +1467,7 @@ The statement below inspects every expression within the AST of a single type-checked file and prints its type, value, and mode: - // go get github.com/golang/example/gotypes/typeandvalue + // go get golang.org/x/example/gotypes/typeandvalue ``` // f is a parsed, type-checked *ast.File. @@ -1517,7 +1517,7 @@ the program prints: ``` -$ go build github.com/golang/example/gotypes/typeandvalue +$ go build golang.org/x/example/gotypes/typeandvalue $ ./typeandvalue make(map[string]int) mode: value type: map[string]int @@ -1573,7 +1573,7 @@ call `x.f()` was intended; comparing a method `x.f` against nil is a common mistake. - // go get github.com/golang/example/gotypes/nilfunc + // go get golang.org/x/example/gotypes/nilfunc ``` // CheckNilFuncComparison reports unintended comparisons @@ -1640,7 +1640,7 @@ the program reports these errors: ``` -$ go build github.com/golang/example/gotypes/nilfunc +$ go build golang.org/x/example/gotypes/nilfunc $ ./nilfunc input.go:7:5: comparison of function Bytes == nil is always false input.go:7:25: comparison of function Repeat != nil is always true @@ -1894,7 +1894,7 @@ The `main` function (not shown) loads the specified package and calls `PrintSkeleton` with the remaining two arguments: - // go get github.com/golang/example/gotypes/skeleton + // go get golang.org/x/example/gotypes/skeleton ``` func PrintSkeleton(pkg *types.Package, ifacename, concname string) error { @@ -1968,7 +1968,7 @@ The following program inspects all pairs of package-level named types in `pkg`, and reports the types that satisfy each interface type. - // go get github.com/golang/example/gotypes/implements + // go get golang.org/x/example/gotypes/implements ``` // Find all named types at package level. @@ -2000,7 +2000,7 @@ for _, T := range allNamed { Given this input, - // go get github.com/golang/example/gotypes/implements + // go get golang.org/x/example/gotypes/implements ``` const input = `package main @@ -2022,7 +2022,7 @@ the program prints: ``` -$ go build github.com/golang/example/gotypes/implements +$ go build golang.org/x/example/gotypes/implements $ ./implements *hello.A satisfies hello.I hello.B satisfies hello.I @@ -2177,7 +2177,7 @@ Such a tool could help identify inefficient parameter passing in your programs. - // go get github.com/golang/example/gotypes/hugeparam + // go get golang.org/x/example/gotypes/hugeparam ``` var bytesFlag = flag.Int("bytes", 48, "maximum parameter size in bytes") @@ -2336,7 +2336,7 @@ Here's the first part of the program, showing how to load an entire program starting from the single package, `pkgpath`: - // go get github.com/golang/example/gotypes/doc + // go get golang.org/x/example/gotypes/doc ``` pkgpath, name := os.Args[1], os.Args[2] @@ -2362,7 +2362,7 @@ Notice that we instructed the parser to retain comments during parsing. The rest of the program prints the output: - // go get github.com/golang/example/gotypes/doc + // go get golang.org/x/example/gotypes/doc ``` // Print the object and its methods (incl. location of definition). diff --git a/gotypes/weave.go b/gotypes/weave.go index 770bda2..cfaa57b 100644 --- a/gotypes/weave.go +++ b/gotypes/weave.go @@ -77,7 +77,7 @@ func main() { // Show caption unless '-' follows. if len(words) < 4 || words[3] != "-" { - fmt.Printf(" // go get github.com/golang/example/gotypes/%s\n\n", + fmt.Printf(" // go get golang.org/x/example/gotypes/%s\n\n", filepath.Dir(filename)) }