forked from goffee/goffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goffee.go
131 lines (114 loc) · 3.21 KB
/
goffee.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"flag"
"log"
"github.com/gophergala/goffee/Godeps/_workspace/src/github.com/gorilla/sessions"
"github.com/gophergala/goffee/Godeps/_workspace/src/golang.org/x/oauth2"
"github.com/gophergala/goffee/Godeps/_workspace/src/golang.org/x/oauth2/github"
"github.com/gophergala/goffee/data"
"github.com/gophergala/goffee/notifier"
"github.com/gophergala/goffee/probe"
"github.com/gophergala/goffee/queue"
"github.com/gophergala/goffee/scheduler"
"github.com/gophergala/goffee/web"
"github.com/gophergala/goffee/web/controllers"
"github.com/gophergala/goffee/writer"
)
var webMode bool
var probeMode bool
var schedulerMode bool
var writerMode bool
var notifierMode bool
var redisAddress string
var bind string
var mysql string
func init() {
var gitHubClientID string
var gitHubClientSecret string
var mandrillKey string
var sessionSecret string
flag.BoolVar(&webMode, "webmode", false, "Run goffee in webmode")
flag.BoolVar(&probeMode, "torfetch", false, "Fetch something via Tor")
flag.BoolVar(&schedulerMode, "scheduler", false, "Run goffee scheduler")
flag.BoolVar(&writerMode, "writer", false, "Run goffee writer")
flag.BoolVar(¬ifierMode, "notifier", false, "Run goffee notifier")
flag.StringVar(&redisAddress, "redisaddress", "127.0.0.1:6379", "Address of redis including port")
flag.StringVar(&bind, "bind", "127.0.0.1:8000", "Address to bind to")
flag.StringVar(&gitHubClientID, "clientid", "", "Github client ID")
flag.StringVar(&gitHubClientSecret, "secret", "", "GitHub client Secret")
flag.StringVar(&mandrillKey, "mandrill", "", "Mandrill API key")
flag.StringVar(&mysql, "mysql", "", "MySQL connection string")
flag.StringVar(&sessionSecret, "sessionsecret", "", "The session secret for the web UI")
flag.Parse()
// If no mode has been defined, just launch them all!
if !webMode && !probeMode && !schedulerMode && !writerMode && !notifierMode {
webMode = true
probeMode = true
schedulerMode = true
writerMode = true
notifierMode = true
}
if notifierMode {
if mandrillKey == "" {
log.Fatal("No Mandrill API key set!")
}
notifier.MandrillKey = mandrillKey
}
if webMode {
if gitHubClientID == "" || gitHubClientSecret == "" {
log.Fatal("No GitHub clientid or secret set!")
}
controllers.OAuthConf = &oauth2.Config{
ClientID: gitHubClientID,
ClientSecret: gitHubClientSecret,
Scopes: []string{"user:email"},
Endpoint: github.Endpoint,
}
if sessionSecret == "" {
log.Fatal("No session secret set!")
}
web.SessionStore = sessions.NewCookieStore([]byte(sessionSecret))
}
}
func main() {
if webMode {
web.StartServer(bind)
}
if probeMode || schedulerMode || writerMode || notifierMode {
queue.InitQueue(redisAddress)
}
if webMode || schedulerMode || writerMode || notifierMode {
if mysql != "" {
data.InitDatabase("mysql", mysql)
} else {
data.InitDatabase("sqlite3", "/tmp/goffee.db")
}
}
if probeMode {
probe.Run()
}
if schedulerMode {
scheduler.Run()
}
if writerMode {
writer.Run()
}
if notifierMode {
notifier.Run()
}
if webMode {
web.Wait()
}
if writerMode {
writer.Wait()
}
if schedulerMode {
scheduler.Wait()
}
if probeMode {
probe.Wait()
}
if notifierMode {
notifier.Wait()
}
}