-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (63 loc) · 2.07 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"github.com/korfuri/goref"
"github.com/korfuri/goref/elasticsearch"
log "github.com/sirupsen/logrus"
elastic "gopkg.in/olivere/elastic.v5"
)
const (
// Usage help line
Usage = `index -include_tests <true|false> \\
-elastic_url http://localhost:9200/ -elastic_user elastic -elastic_password changeme \\
github.com/korfuri/goref github.com/korfuri/goref/elastic/main`
)
var (
includeTests = flag.Bool("include_tests", true,
"Whether XTest packages should be included in the index.")
elasticURL = flag.String("elastic_url", "http://localhost:9200",
"URL of the ElasticSearch cluster.")
elasticUsername = flag.String("elastic_user", "elastic",
"Username to authenticate with ElasticSearch.")
elasticPassword = flag.String("elastic_password", "changeme",
"Password to authenticate with ElasticSearch.")
elasticIndex = flag.String("elastic_index", "goref",
"Name of the index to use in ElasticSearch.")
)
func usage() {
log.Fatal(Usage)
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
usage()
}
// Create a client
eClient, err := elastic.NewClient(
elastic.SetURL(*elasticURL),
elastic.SetBasicAuth(*elasticUsername, *elasticPassword))
if err != nil {
log.Fatal(err)
}
client := elasticsearch.NewClient(eClient, *elasticIndex)
packages := args
// Index the requested packages
log.Infof("Indexing packages: %v", packages)
if *includeTests {
log.Info("This index will include XTests.")
}
pg := goref.NewPackageGraph(goref.FileMTimeVersion)
// Set FilterF to skip any packages that exist in our index
pg.SetFilterF(elasticsearch.FilterF(client))
pg.LoadPackages(packages, *includeTests)
log.Info("Computing the interface-implementation matrix.")
pg.ComputeInterfaceImplementationMatrix()
log.Infof("%d packages in the graph.", len(pg.Packages))
// Load the indexed references into ElasticSearch
log.Info("Inserting references into ElasticSearch.")
if err := elasticsearch.LoadGraphToElastic(*pg, client); err != nil {
log.Fatalf("Couldn't load some references. Error: %s", err)
}
log.Info("Done, bye.")
}