-
Notifications
You must be signed in to change notification settings - Fork 0
/
felo.go
58 lines (52 loc) · 1.05 KB
/
felo.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
package main
import (
// std
"fmt"
"os"
// local modules
"webscope.io/felo/modules/server"
"webscope.io/felo/modules/slack"
// external modules
"github.com/joho/godotenv"
)
type ENV struct {
BOT_TOKEN string
ENV string
PORT string
}
func readEnv() (ENV, error) {
envMap := map[string]string{}
envKeys := []string{
"BOT_TOKEN",
"ENV",
"PORT",
}
localEnv, envErr := godotenv.Read(".env")
for _, key := range envKeys {
// Atempt to get OS level ENV variable
val := os.Getenv(key)
if val == "" {
// If not found, attempt to read from .env file
if envErr != nil || localEnv[key] == "" {
return ENV{}, fmt.Errorf("missing environment variable %s", key)
} else {
val = localEnv[key]
}
}
envMap[key] = val
}
return ENV{
BOT_TOKEN: envMap["BOT_TOKEN"],
ENV: envMap["ENV"],
PORT: envMap["PORT"],
}, nil
}
func main() {
env, err := readEnv()
if err != nil {
fmt.Println("Error reading .env file")
panic(err)
}
client := slack.New(env.BOT_TOKEN)
server.New(env.ENV, env.PORT, client)
}