-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
76 lines (63 loc) · 1.41 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
76
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/OhYee/blotter/api"
"github.com/OhYee/blotter/cron"
"github.com/OhYee/blotter/http"
"github.com/OhYee/blotter/output"
"github.com/OhYee/blotter/register"
"github.com/OhYee/blotter/utils/initial"
"github.com/OhYee/blotter/utils/reaper"
)
var (
addr = "127.0.0.1:50000"
prefix = "/api/"
tool = ""
url = ""
)
var (
_version string
)
//go:generate /bin/bash ./generate.bash
func parseFlags() {
flag.StringVar(&addr, "address", "127.0.0.1:50000", "listen address")
flag.StringVar(&prefix, "prefix", "/api/", "api url prefix")
flag.StringVar(&url, "url", "", "spider url")
keys := make([]string, len(cron.CronMap))
pos := 0
for k, _ := range cron.CronMap {
keys[pos] = k
pos++
}
flag.StringVar(&tool, "tool", "", fmt.Sprintf("call tools(%s)", strings.Join(keys, ",")))
flag.Parse()
}
func main() {
go reaper.Reap()
parseFlags()
register.SetContext("version", _version)
register.SetContext("spiderURL", url)
if tool != "" {
f, e := cron.CronMap[tool]
if !e {
output.ErrOutput.Printf("No tool named %s\n", tool)
os.Exit(1)
}
f()
os.Exit(0)
return
}
cron.Start()
defer cron.Stop()
api.Register()
initial.Run()
// queue.Register().Register("extensions/queue")
// register.DebugApiMap()
output.Log("Server will start at http://%s", addr)
if err := http.Server(addr, prefix); err != nil {
output.Err(err)
}
}