@@ -143,7 +143,7 @@ run `go get golang.org/x/example/gotypes/...`.
143
143
144
144
// go get golang.org/x/example/gotypes/pkginfo
145
145
146
- ```
146
+ ``` go
147
147
package main
148
148
149
149
import (
@@ -247,7 +247,7 @@ Finally, the program prints the attributes of the package, shown below.
247
247
(The hexadecimal number may vary from one run to the next.)
248
248
249
249
250
- ```
250
+ ``` go
251
251
$ go build golang.org /x/example/gotypes/pkginfo
252
252
$ ./pkginfo
253
253
Package " cmd/hello"
@@ -505,7 +505,7 @@ identifier in the input program, and the object it refers to.
505
505
506
506
// go get golang.org/x/example/gotypes/defsuses
507
507
508
- ```
508
+ ``` go
509
509
func PrintDefsUses (fset *token .FileSet , files ...*ast .File ) error {
510
510
conf := types.Config {Importer: importer.Default ()}
511
511
info := &types.Info {
@@ -535,7 +535,7 @@ Let's use the _hello, world_ program again as the input:
535
535
536
536
// go get golang.org/x/example/gotypes/hello
537
537
538
- ```
538
+ ``` go
539
539
package main
540
540
541
541
import " fmt"
@@ -549,7 +549,7 @@ func main() {
549
549
This is what it prints:
550
550
551
551
552
- ```
552
+ ``` go
553
553
$ go build golang.org /x/example/gotypes/defsuses
554
554
$ ./defsuses
555
555
hello.go :1 :9 : " main" defines <nil >
@@ -796,7 +796,7 @@ preserve comments in the input.
796
796
797
797
// go get golang.org/x/example/gotypes/lookup
798
798
799
- ```
799
+ ``` go
800
800
func main () {
801
801
fset := token.NewFileSet ()
802
802
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,
839
839
and so on.
840
840
841
841
842
- ```
842
+ ``` go
843
843
const hello = `
844
844
package main
845
845
@@ -863,7 +863,7 @@ func main() {
863
863
Here's the output:
864
864
865
865
866
- ```
866
+ ``` go
867
867
$ go build golang.org /x/example/gotypes/lookup
868
868
$ ./lookup
869
869
At hello.go :6 :1 , " append" = builtin append
@@ -1566,7 +1566,7 @@ type-checked file and prints its type, value, and mode:
1566
1566
1567
1567
// go get golang.org/x/example/gotypes/typeandvalue
1568
1568
1569
- ```
1569
+ ``` go
1570
1570
// f is a parsed, type-checked *ast.File.
1571
1571
ast.Inspect (f, func (n ast.Node ) bool {
1572
1572
if expr , ok := n.(ast.Expr ); ok {
@@ -1596,7 +1596,7 @@ It makes use of these two helper functions, which are not shown:
1596
1596
Given this input:
1597
1597
1598
1598
1599
- ```
1599
+ ``` go
1600
1600
const input = `
1601
1601
package main
1602
1602
@@ -1613,7 +1613,7 @@ func main() {
1613
1613
the program prints:
1614
1614
1615
1615
1616
- ```
1616
+ ``` go
1617
1617
$ go build golang.org /x/example/gotypes/typeandvalue
1618
1618
$ ./typeandvalue
1619
1619
make (map [string ]int ) mode: value
@@ -1672,7 +1672,7 @@ comparing a method `x.f` against nil is a common mistake.
1672
1672
1673
1673
// go get golang.org/x/example/gotypes/nilfunc
1674
1674
1675
- ```
1675
+ ``` go
1676
1676
// CheckNilFuncComparison reports unintended comparisons
1677
1677
// of functions against nil, e.g., "if x.Method == nil {".
1678
1678
func CheckNilFuncComparison (info *types .Info , n ast .Node ) {
@@ -1718,7 +1718,7 @@ func CheckNilFuncComparison(info *types.Info, n ast.Node) {
1718
1718
Given this input,
1719
1719
1720
1720
1721
- ```
1721
+ ``` go
1722
1722
const input = ` package main
1723
1723
1724
1724
import "bytes"
@@ -1736,7 +1736,7 @@ func main() {
1736
1736
the program reports these errors:
1737
1737
1738
1738
1739
- ```
1739
+ ``` go
1740
1740
$ go build golang.org /x/example/gotypes/nilfunc
1741
1741
$ ./nilfunc
1742
1742
input.go :7 :5 : comparison of function Bytes == nil is always false
@@ -1969,7 +1969,7 @@ interface.
1969
1969
Here's an example:
1970
1970
1971
1971
1972
- ```
1972
+ ``` go
1973
1973
$ ./skeleton io ReadWriteCloser buffer
1974
1974
// *buffer implements io.ReadWriteCloser.
1975
1975
type buffer struct {}
@@ -1993,7 +1993,7 @@ calls `PrintSkeleton` with the remaining two arguments:
1993
1993
1994
1994
// go get golang.org/x/example/gotypes/skeleton
1995
1995
1996
- ```
1996
+ ``` go
1997
1997
func PrintSkeleton (pkg *types .Package , ifacename , concname string ) error {
1998
1998
obj := pkg.Scope ().Lookup (ifacename)
1999
1999
if obj == nil {
@@ -2051,7 +2051,7 @@ Passing `(*types.Package).Name` causes only the package name
2051
2051
Here's another example that illustrates it:
2052
2052
2053
2053
2054
- ```
2054
+ ``` go
2055
2055
$ ./skeleton net/http Handler myHandler
2056
2056
// *myHandler implements net/http.Handler.
2057
2057
type myHandler struct {}
@@ -2067,7 +2067,7 @@ in `pkg`, and reports the types that satisfy each interface type.
2067
2067
2068
2068
// go get golang.org/x/example/gotypes/implements
2069
2069
2070
- ```
2070
+ ``` go
2071
2071
// Find all named types at package level.
2072
2072
var allNamed []*types.Named
2073
2073
for _ , name := range pkg.Scope ().Names () {
@@ -2099,7 +2099,7 @@ Given this input,
2099
2099
2100
2100
// go get golang.org/x/example/gotypes/implements
2101
2101
2102
- ```
2102
+ ``` go
2103
2103
const input = ` package main
2104
2104
2105
2105
type A struct{}
@@ -2118,7 +2118,7 @@ type J interface { g() }
2118
2118
the program prints:
2119
2119
2120
2120
2121
- ```
2121
+ ``` go
2122
2122
$ go build golang.org /x/example/gotypes/implements
2123
2123
$ ./implements
2124
2124
*hello.A satisfies hello.I
@@ -2276,7 +2276,7 @@ programs.
2276
2276
2277
2277
// go get golang.org/x/example/gotypes/hugeparam
2278
2278
2279
- ```
2279
+ ``` go
2280
2280
var bytesFlag = flag.Int (" bytes" , 48 , " maximum parameter size in bytes" )
2281
2281
2282
2282
func 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
2324
2324
is copied.
2325
2325
2326
2326
2327
- ```
2327
+ ``` go
2328
2328
% ./hugeparam encoding/xml
2329
2329
/go /src/encoding/xml/marshal.go :167 :50 : " start" parameter: encoding/xml.StartElement = 56 bytes
2330
2330
/go /src/encoding/xml/marshal.go :734 :97 : " " result: encoding/xml.StartElement = 56 bytes
@@ -2408,7 +2408,7 @@ the command line.
2408
2408
Here's an example:
2409
2409
2410
2410
2411
- ```
2411
+ ``` go
2412
2412
$ ./doc net/http File
2413
2413
type 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 }
2414
2414
$GOROOT/src/io/io.go :92 :2 : method (net/http.File ) Close () error
@@ -2435,7 +2435,7 @@ plus exported type information for its dependencies.
2435
2435
2436
2436
// go get golang.org/x/example/gotypes/doc
2437
2437
2438
- ```
2438
+ ```go
2439
2439
pkgpath, name := os.Args[1], os.Args[2]
2440
2440
2441
2441
// Load complete type information for the specified packages,
@@ -2465,7 +2465,7 @@ The rest of the program prints the output:
2465
2465
2466
2466
// go get golang.org/x/example/gotypes/doc
2467
2467
2468
- ```
2468
+ ```go
2469
2469
// Print the object and its methods (incl. location of definition).
2470
2470
fmt.Println(obj)
2471
2471
for _, sel := range typeutil.IntuitiveMethodSet(obj.Type(), nil) {
0 commit comments