-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobals.go
49 lines (39 loc) · 1.14 KB
/
globals.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
package main
import (
"log"
"os"
"github.com/joho/godotenv"
tb "gopkg.in/tucnak/telebot.v2"
)
var (
envBotToken string
envListenPort string
envRootPublicURL string
botMode string
publicURL string
rootTelegramMethodURL string
mongoHostname string
mongoPort string
currentLimboUsers map[int]*tb.Message = make(map[int]*tb.Message)
)
// Simple helper function to read an environment or return a default value
func getEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}
func init() {
err := godotenv.Overload(".env.default", ".env")
if err != nil {
log.Fatal("Error loading .env file")
}
envBotToken = os.Getenv("BOT_TOKEN")
rootTelegramMethodURL = "https://api.telegram.org/bot" + envBotToken
envRootPublicURL = os.Getenv("ROOT_PUBLIC_URL")
publicURL = envRootPublicURL + "/" + envBotToken
envListenPort = getEnv("LISTEN_PORT", "9000")
botMode = getEnv("BOT_MODE", "development")
mongoHostname = getEnv("MONGO_HOSTNAME", "localhost")
mongoPort = getEnv("MONGO_PORT", "27017")
}