/
main.go
42 lines (38 loc) · 1011 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
package main
import (
"encoding/json"
"github.com/ericflo/irlmoji/src"
"io/ioutil"
"log"
"os"
)
const ENV_WARNING string = ("WARNING: Could not read env.json file, so unless " +
"you've set the environment variables manually, the app will not work.")
// Reads env.json, which should contain a single JSON object, and adds all the
// key/value pairs from that object into the environment as environment
// variables. Ideally this would be done by something like envdir, but this is
// a bit easier.
func readEnv() {
file, err := ioutil.ReadFile("./env.json")
if err != nil {
log.Println(err.Error())
log.Println(ENV_WARNING)
return
}
var env map[string]string
if err = json.Unmarshal(file, &env); err != nil {
log.Println(err.Error())
log.Println(ENV_WARNING)
return
}
for key, value := range env {
if err = os.Setenv(key, value); err != nil {
log.Println("WARNING: Could not set environment variable", key,
"to", value)
}
}
}
func main() {
readEnv()
irlmoji.Main()
}