-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
52 lines (40 loc) · 980 Bytes
/
utils.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
package main
import (
"fmt"
"strings"
)
func parseEnvLine(line string) (string, string, error) {
line = strings.TrimSpace(line)
if line == "" {
return "", "", nil
}
if strings.HasPrefix(line, "#") {
return "", "", nil
}
key, value, found := strings.Cut(line, "=")
if !found {
return "", "", fmt.Errorf("invalid environment line: key=value separator not found: %q", line)
}
key = strings.ToUpper(strings.TrimSpace(key))
if key == "" {
return "", "", fmt.Errorf("key empty for environment line: %q", line)
}
value = strings.TrimSpace(value)
if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") {
value = strings.TrimPrefix(value, "\"")
value = strings.TrimSuffix(value, "\"")
}
return key, value, nil
}
func copyMap(m map[string]any) map[string]any {
cp := make(map[string]interface{})
for k, v := range m {
vm, ok := v.(map[string]interface{})
if ok {
cp[k] = copyMap(vm)
} else {
cp[k] = v
}
}
return cp
}