...
1
2
3
4
5 package main
6
7 import (
8 "fmt"
9 "go/build"
10 "go/parser"
11
12 "golang.org/x/tools/go/loader"
13 )
14
15 const (
16 extractFile = "extracted.gotext.json"
17 outFile = "out.gotext.json"
18 gotextSuffix = ".gotext.json"
19 )
20
21
22 var (
23 wrap = func(err error, msg string) error {
24 if err == nil {
25 return nil
26 }
27 return fmt.Errorf("%s: %v", msg, err)
28 }
29 errorf = fmt.Errorf
30 )
31
32
33 func loadPackages(conf *loader.Config, args []string) (*loader.Program, error) {
34 if len(args) == 0 {
35 args = []string{"."}
36 }
37
38 conf.Build = &build.Default
39 conf.ParserMode = parser.ParseComments
40
41
42 args, err := conf.FromArgs(args, false)
43 if err != nil {
44 return nil, wrap(err, "loading packages failed")
45 }
46
47
48 return conf.Load()
49 }
50
View as plain text