-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
59 lines (49 loc) · 1.25 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
// Brief: Main entry point of the bot Web App
// Primary responsibility: Receive and identify handler to delegate to
package main
import (
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/julwrites/BotPlatform/pkg/secrets"
"github.com/julwrites/ScriptureBot/pkg/bot"
)
func bothandler(res http.ResponseWriter, req *http.Request) {
secretsPath := "/go/bin/secrets.yaml"
secretsData, err := secrets.LoadSecrets(secretsPath)
if err != nil {
panic(err)
}
switch strings.Trim(req.URL.EscapedPath(), "\n") {
case strings.Trim("/"+secretsData.TELEGRAM_ID, "\n"):
log.Printf("Incoming telegram message")
bot.TelegramHandler(res, req, &secretsData)
break
default:
log.Printf("No appropriate handler")
}
}
func subscriptionhandler() {
secretsPath := "/go/bin/secrets.yaml"
secretsData, err := secrets.LoadSecrets(secretsPath)
if err != nil {
panic(err)
}
bot.SubscriptionHandler(&secretsData)
}
func main() {
if os.Getenv("MODE") == "subscription" {
subscriptionhandler()
} else {
http.HandleFunc("/", bothandler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
log.Printf("Listening on port %s", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
}