-
Notifications
You must be signed in to change notification settings - Fork 1
/
apec.go
103 lines (91 loc) · 2.25 KB
/
apec.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/alecthomas/kingpin"
"github.com/pkg/profile"
)
var (
app = kingpin.New("apec", "APEC crawler, indexer and query tool")
dataDir = app.Flag("data", "data directory").Default("offers").String()
prof = app.Flag("profile", "enable profiling").Bool()
)
type Config struct {
RootDir string
}
func NewConfig(rootDir string) *Config {
return &Config{
RootDir: rootDir,
}
}
func (d *Config) Store() string {
return filepath.Join(d.RootDir, "offers")
}
func (d *Config) Index() string {
return filepath.Join(d.RootDir, "index")
}
func (d *Config) Queue() string {
return filepath.Join(d.RootDir, "queue")
}
func (d *Config) Geocoder() string {
return filepath.Join(d.RootDir, "geocoder")
}
func (d *Config) GeocodingKey() string {
return os.Getenv("APEC_GEOCODING_KEY")
}
func dispatch() error {
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
if *prof {
defer profile.Start(profile.CPUProfile).Stop()
}
cfg := NewConfig(*dataDir)
switch cmd {
case crawlCmd.FullCommand():
return crawlFn(cfg)
case indexCmd.FullCommand():
return indexOffers(cfg)
case searchCmd.FullCommand():
return search(cfg)
case webCmd.FullCommand():
return web(cfg)
case geocodeCmd.FullCommand():
return geocode(cfg)
case upgradeCmd.FullCommand():
return upgrade(cfg)
case dumpDeletedCmd.FullCommand():
return dumpDeletedOffersFn(cfg)
case changesCmd.FullCommand():
return changesFn(cfg)
case spatialCmd.FullCommand():
return spatialFn(cfg)
case debugQueryCmd.FullCommand():
return debugQueryFn(cfg)
case analyzeCmd.FullCommand():
return analyzeFn(cfg)
case geocodedCmd.FullCommand():
return geocodedFn(cfg)
case densityCmd.FullCommand():
return densityFn(cfg)
case histogramCmd.FullCommand():
return histogramFn(cfg)
case indexStatsCmd.FullCommand():
return indexStatsFn(cfg)
case listDeletedCmd.FullCommand():
return listDeletedFn(cfg)
case duplicatesCmd.FullCommand():
return duplicatesFn(cfg)
case dumpOfferCmd.FullCommand():
return dumpOfferFn(cfg)
case dumpOffersCmd.FullCommand():
return dumpOffersFn(cfg)
}
return fmt.Errorf("unknown command: %s", cmd)
}
func main() {
err := dispatch()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}