/
app.go
54 lines (47 loc) · 1.11 KB
/
app.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
/*
rsstotwitter is an application that checks for new RSS posts
and posts them to the corresponding Twitter account.
*/
package main
import (
"fmt"
"github.com/gokyle/gomon/monitor"
"github.com/gokyle/rsstotwitter/bot"
"github.com/gokyle/rsstotwitter/frontend"
"log"
"os"
)
// run is stubbed
func validate_env_var(name string) bool {
value := os.Getenv(name)
if value == "" {
return false
}
return true
}
// should check to ensure required environment variables are present
func validate_environment() {
vars := []string{"TW_CKEY", "TW_CSEC", "TW_ATOK", "TW_ASEC",
"PG_DBNAME", "PG_USER", "PG_PASS", "PG_HOST",
"PG_PORT", "PG_SSLMODE"}
for _, name := range vars {
if !validate_env_var(name) {
panic(fmt.Sprintf("missing environment variable: %s",
name))
}
}
}
func init() {
validate_environment()
monitor.ConfigFromEnv()
if !monitor.EmailEnabled() {
log.Fatal("[!] error configuring monitor: mail not configured")
}
if !monitor.PushoverEnabled() {
log.Fatal("[!] error configuring monitor: pushover not configured")
}
}
func main() {
go monitor.Monitor(bot.Run)
frontend.HttpServer()
}