@@ -143,7 +143,7 @@ run `go get golang.org/x/example/gotypes/...`.
143143
144144 // go get golang.org/x/example/gotypes/pkginfo
145145
146- ```
146+ ``` go
147147package main
148148
149149import (
@@ -247,7 +247,7 @@ Finally, the program prints the attributes of the package, shown below.
247247(The hexadecimal number may vary from one run to the next.)
248248
249249
250- ```
250+ ``` go
251251$ go build golang.org /x/example/gotypes/pkginfo
252252$ ./pkginfo
253253Package " cmd/hello"
@@ -505,7 +505,7 @@ identifier in the input program, and the object it refers to.
505505
506506 // go get golang.org/x/example/gotypes/defsuses
507507
508- ```
508+ ``` go
509509func PrintDefsUses (fset *token .FileSet , files ...*ast .File ) error {
510510 conf := types.Config {Importer: importer.Default ()}
511511 info := &types.Info {
@@ -535,7 +535,7 @@ Let's use the _hello, world_ program again as the input:
535535
536536 // go get golang.org/x/example/gotypes/hello
537537
538- ```
538+ ``` go
539539package main
540540
541541import " fmt"
@@ -549,7 +549,7 @@ func main() {
549549This is what it prints:
550550
551551
552- ```
552+ ``` go
553553$ go build golang.org /x/example/gotypes/defsuses
554554$ ./defsuses
555555hello.go :1 :9 : " main" defines <nil >
@@ -796,7 +796,7 @@ preserve comments in the input.
796796
797797 // go get golang.org/x/example/gotypes/lookup
798798
799- ```
799+ ``` go
800800func main () {
801801 fset := token.NewFileSet ()
802802 f , err := parser.ParseFile (fset, " hello.go" , hello, parser.ParseComments )
@@ -839,7 +839,7 @@ The second comment looks up `"fmt"` in the `main` function's block,
839839and so on.
840840
841841
842- ```
842+ ``` go
843843const hello = `
844844package main
845845
@@ -863,7 +863,7 @@ func main() {
863863Here's the output:
864864
865865
866- ```
866+ ``` go
867867$ go build golang.org /x/example/gotypes/lookup
868868$ ./lookup
869869At hello.go :6 :1 , " append" = builtin append
@@ -1566,7 +1566,7 @@ type-checked file and prints its type, value, and mode:
15661566
15671567 // go get golang.org/x/example/gotypes/typeandvalue
15681568
1569- ```
1569+ ``` go
15701570// f is a parsed, type-checked *ast.File.
15711571ast.Inspect (f, func (n ast.Node ) bool {
15721572 if expr , ok := n.(ast.Expr ); ok {
@@ -1596,7 +1596,7 @@ It makes use of these two helper functions, which are not shown:
15961596Given this input:
15971597
15981598
1599- ```
1599+ ``` go
16001600const input = `
16011601package main
16021602
@@ -1613,7 +1613,7 @@ func main() {
16131613the program prints:
16141614
16151615
1616- ```
1616+ ``` go
16171617$ go build golang.org /x/example/gotypes/typeandvalue
16181618$ ./typeandvalue
16191619make (map [string ]int ) mode: value
@@ -1672,7 +1672,7 @@ comparing a method `x.f` against nil is a common mistake.
16721672
16731673 // go get golang.org/x/example/gotypes/nilfunc
16741674
1675- ```
1675+ ``` go
16761676// CheckNilFuncComparison reports unintended comparisons
16771677// of functions against nil, e.g., "if x.Method == nil {".
16781678func CheckNilFuncComparison (info *types .Info , n ast .Node ) {
@@ -1718,7 +1718,7 @@ func CheckNilFuncComparison(info *types.Info, n ast.Node) {
17181718Given this input,
17191719
17201720
1721- ```
1721+ ``` go
17221722const input = ` package main
17231723
17241724import "bytes"
@@ -1736,7 +1736,7 @@ func main() {
17361736the program reports these errors:
17371737
17381738
1739- ```
1739+ ``` go
17401740$ go build golang.org /x/example/gotypes/nilfunc
17411741$ ./nilfunc
17421742input.go :7 :5 : comparison of function Bytes == nil is always false
@@ -1969,7 +1969,7 @@ interface.
19691969Here's an example:
19701970
19711971
1972- ```
1972+ ``` go
19731973$ ./skeleton io ReadWriteCloser buffer
19741974// *buffer implements io.ReadWriteCloser.
19751975type buffer struct {}
@@ -1993,7 +1993,7 @@ calls `PrintSkeleton` with the remaining two arguments:
19931993
19941994 // go get golang.org/x/example/gotypes/skeleton
19951995
1996- ```
1996+ ``` go
19971997func PrintSkeleton (pkg *types .Package , ifacename , concname string ) error {
19981998 obj := pkg.Scope ().Lookup (ifacename)
19991999 if obj == nil {
@@ -2051,7 +2051,7 @@ Passing `(*types.Package).Name` causes only the package name
20512051Here's another example that illustrates it:
20522052
20532053
2054- ```
2054+ ``` go
20552055$ ./skeleton net/http Handler myHandler
20562056// *myHandler implements net/http.Handler.
20572057type myHandler struct {}
@@ -2067,7 +2067,7 @@ in `pkg`, and reports the types that satisfy each interface type.
20672067
20682068 // go get golang.org/x/example/gotypes/implements
20692069
2070- ```
2070+ ``` go
20712071// Find all named types at package level.
20722072var allNamed []*types.Named
20732073for _ , name := range pkg.Scope ().Names () {
@@ -2099,7 +2099,7 @@ Given this input,
20992099
21002100 // go get golang.org/x/example/gotypes/implements
21012101
2102- ```
2102+ ``` go
21032103const input = ` package main
21042104
21052105type A struct{}
@@ -2118,7 +2118,7 @@ type J interface { g() }
21182118the program prints:
21192119
21202120
2121- ```
2121+ ``` go
21222122$ go build golang.org /x/example/gotypes/implements
21232123$ ./implements
21242124*hello.A satisfies hello.I
@@ -2276,7 +2276,7 @@ programs.
22762276
22772277 // go get golang.org/x/example/gotypes/hugeparam
22782278
2279- ```
2279+ ``` go
22802280var bytesFlag = flag.Int (" bytes" , 48 , " maximum parameter size in bytes" )
22812281
22822282func PrintHugeParams (fset *token .FileSet , info *types .Info , sizes types .Sizes , files []*ast .File ) {
@@ -2324,7 +2324,7 @@ It reports a number of places where the 7-word
23242324is copied.
23252325
23262326
2327- ```
2327+ ``` go
23282328% ./hugeparam encoding/xml
23292329/go /src/encoding/xml/marshal.go :167 :50 : " start" parameter: encoding/xml.StartElement = 56 bytes
23302330/go /src/encoding/xml/marshal.go :734 :97 : " " result: encoding/xml.StartElement = 56 bytes
@@ -2408,7 +2408,7 @@ the command line.
24082408Here's an example:
24092409
24102410
2411- ```
2411+ ``` go
24122412$ ./doc net/http File
24132413type net/http.File interface {Readdir (count int ) ([]os.FileInfo , error ); Seek (offset int64 , whence int ) (int64 , error ); Stat () (os.FileInfo , error ); io.Closer ; io.Reader }
24142414$GOROOT/src/io/io.go :92 :2 : method (net/http.File ) Close () error
@@ -2435,7 +2435,7 @@ plus exported type information for its dependencies.
24352435
24362436 // go get golang.org/x/example/gotypes/doc
24372437
2438- ```
2438+ ```go
24392439pkgpath, name := os.Args[1], os.Args[2]
24402440
24412441// Load complete type information for the specified packages,
@@ -2465,7 +2465,7 @@ The rest of the program prints the output:
24652465
24662466 // go get golang.org/x/example/gotypes/doc
24672467
2468- ```
2468+ ```go
24692469// Print the object and its methods (incl. location of definition).
24702470fmt.Println(obj)
24712471for _, sel := range typeutil.IntuitiveMethodSet(obj.Type(), nil) {
0 commit comments