-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (40 loc) · 964 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
47
48
49
50
51
52
package main
import (
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"twitter-meme-bot/database"
"twitter-meme-bot/reddit"
"twitter-meme-bot/twitter"
"twitter-meme-bot/web"
"log"
"net/http"
"os"
"time"
)
func main() {
// register .env variables
err := godotenv.Load()
if err != nil {
print("Error loading .env file continuing with normal os env variables")
}
database.Connect()
twitter.Setup();
println("Bot starting...")
go twitter.StartStream()
go loopInterval(10)
// http server so we can deploy on Heroku
println("Web server listening on :"+os.Getenv("PORT"));
r := mux.NewRouter()
r = web.RegisterRoutes(*r)
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/static/")))
err = http.ListenAndServe(":"+os.Getenv("PORT"), r)
if err != nil {
log.Fatal(err)
}
}
func loopInterval(interval time.Duration) {
reddit.GetThreads(true)
for range time.Tick(time.Second * interval){
reddit.GetThreads(true)
}
}