-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.go
executable file
·63 lines (52 loc) · 1.14 KB
/
load.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
60
61
62
63
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"bufio"
"strings"
)
func load() error {
// Open and parse the `.env`
file, err := os.Open(".env")
if err != nil {
log.Fatal(err)
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
Env := map[string]string{}
for scanner.Scan() {
line := scanner.Text()
if !(strings.HasPrefix(line, "#")) {
line := strings.Split(line, "=")
if len(line) != 2 {
continue
}
key := line[0]
value := line[1]
if key == "" {
continue
}
Env[key] = value
}
}
// Read bytes
bytes, err := ioutil.ReadFile("diffenvs.json")
if err != nil {
log.Fatal(err)
return err
}
var EnvMap map[string]([]map[string]string)
json.Unmarshal(bytes, &EnvMap)
if EnvMap == nil {
return nil
}
for _, i := range EnvMap["galactus"] {
for key, value := range i {
os.Setenv(key, Env[value])
}
}
return nil
}