-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (41 loc) · 850 Bytes
/
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
package main
import (
"log"
"github.com/docopt/docopt-go"
"go.etcd.io/bbolt"
"rkfg.me/ns2query/db"
)
var (
bdb *bbolt.DB
)
func main() {
usage := `Usage:
ns2query [-c config]
ns2query --reindex
ns2query -h
Options:
-h --help This help
-c config Use config file [default: config.json]
`
opts, err := docopt.ParseDoc(usage)
if err != nil {
log.Fatal("error parsing arguments:", err)
}
if err := loadConfig(opts["-c"].(string)); err != nil {
log.Fatal("error loading config:", err)
}
if config.BoltDBPath != "" {
if bdb, err = db.OpenBoltDB(config.BoltDBPath); err != nil {
log.Fatal("error opening BoltDB database:", err)
}
db.InitBoltDB(bdb)
defer db.CloseBoltDB(bdb)
}
if b, _ := opts.Bool("--reindex"); b {
db.Reindex(bdb)
}
err = bot()
if err != nil {
log.Fatal("error launching bot:", err)
}
}