/
main.go
54 lines (44 loc) · 1.03 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
package main
import (
"bufio"
"flag"
"fmt"
"go/build"
"log"
"net/http"
"os"
"strings"
)
var (
httpFlag = flag.String("http", ":6118", "HTTP service address, e.g. 'localhost:6118'")
exclFlag = flag.String("exclude", "", "List of directories to exclude from indexing")
rootFlag = flag.String("root", "", "List of root directories containing go packages")
defaultExclusions = `.git .hg`
)
func main() {
flag.Usage = func() {
fmt.Println(`gopaths [-http=[HOST]:PORT] [-exclusions FILE] [-root DIRS]`)
flag.PrintDefaults()
os.Exit(2)
}
flag.Parse()
dirs := index{}
if *exclFlag != "" {
f, err := os.Open(*exclFlag)
if err != nil {
log.Fatalf("%v\n", err)
}
dirs.Exclusions(bufio.NewReader(f))
f.Close()
} else {
dirs.Exclusions(strings.NewReader(defaultExclusions))
}
if *rootFlag != "" {
dirs.Roots(strings.Split(*rootFlag, string(os.PathListSeparator)))
} else {
dirs.Roots(build.Default.SrcDirs())
}
dirs.Index()
go dirs.UpdateIndex()
log.Fatal(http.ListenAndServe(*httpFlag, dirs.ServeMux()))
}