/
app.go
70 lines (61 loc) · 1.45 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
golobsters is an application that checks for new posts on lobste.rs
and posts new posts to the corresponding Twitter account.
*/
package main
import (
"fmt"
"github.com/gokyle/golobsters/bot"
"github.com/gokyle/golobsters/frontend"
"github.com/gokyle/gomon/monitor"
"log"
"net/http"
"os"
"time"
)
var siteURL = "http://lobsternews.kyleisom.net"
// 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 herokuPing() {
for {
log.Println("pinging site")
http.Get(siteURL)
<-time.After(15 * time.Minute)
}
}
func init() {
log.Println("[+] initialising application")
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() {
log.Println("[+] app starting")
go monitor.Monitor(bot.Run)
log.Println("[+] launching web front end")
frontend.HttpServer()
log.Println("[+] app stopping")
}