-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
45 lines (40 loc) · 1.19 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"encoding/json"
"github.com/kisielk/gotool"
"go/build"
"go/parser"
"golang.org/x/tools/go/buildutil"
"golang.org/x/tools/go/loader"
"github.com/yangxikun/guruweb/output"
)
type config struct {
loader loader.Config
scope []string
allPkgs []string
loadedPkgs []string
verbose bool
}
func (c *config) MarshalJSON() ([]byte, error) {
jsonObject := make(map[string]interface{})
jsonObject["inputScopes"] = c.scope
jsonObject["loadedPkgs"] = c.loadedPkgs
jsonObject["verbose"] = c.verbose
return json.Marshal(jsonObject)
}
var defaultConfig = &config{}
func initConfig(scope []string, verbose bool) {
if verbose {
output.Trace("init config")
}
defaultConfig.scope = scope
defaultConfig.allPkgs = gotool.ImportPaths([]string{"all"})
defaultConfig.loadedPkgs = make([]string, 0)
defaultConfig.loader.Build = &build.Default
defaultConfig.loader.Build.CgoEnabled = false
defaultConfig.loader.AllowErrors = true
defaultConfig.loader.ParserMode = parser.AllErrors
defaultConfig.loader.TypeChecker.Error = func(err error) {}
defaultConfig.loader.ImportPkgs = buildutil.ExpandPatterns(defaultConfig.loader.Build, scope)
defaultConfig.verbose = verbose
}