Source file
src/go/parser/example_test.go
1
2
3
4
5 package parser_test
6
7 import (
8 "fmt"
9 "go/parser"
10 "go/token"
11 )
12
13 func ExampleParseFile() {
14 fset := token.NewFileSet()
15
16 src := `package foo
17
18 import (
19 "fmt"
20 "time"
21 )
22
23 func bar() {
24 fmt.Println(time.Now())
25 }`
26
27
28 f, err := parser.ParseFile(fset, "", src, parser.ImportsOnly)
29 if err != nil {
30 fmt.Println(err)
31 return
32 }
33
34
35 for _, s := range f.Imports {
36 fmt.Println(s.Path.Value)
37 }
38
39
40
41
42
43 }
44
View as plain text