-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
56 lines (44 loc) · 1.02 KB
/
init.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
package env
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/joho/godotenv"
)
type initenv struct {}
//Abstract layer get enviroment variable keys and method to load the env files
var (
InitEnv InitEnvInterface = &initenv{}
)
type InitEnvInterface interface {
Read(fileadd string) (string, error)
LoadEnvFile(providePath func() string)
}
// Reads a secret from files from the docker and other container based services
func (ie *initenv) Read(fileadd string) (string, error) {
var secret string
//check if the file is empty
if len(fileadd) == 0 {
return "", nil
}
//read the file
buf, err := ioutil.ReadFile(fileadd)
if err != nil {
return secret, err
}
//convert and assign
secret = strings.TrimSpace(string(buf))
return secret, nil
}
//get the info from local env
func (ie *initenv) LoadEnvFile(providePath func() string) {
//get the path
env := providePath()
fmt.Println(env)
fmt.Println("docker-env:::", os.Getenv("DOCKER_ENV"))
loadErr := godotenv.Load(env)
if loadErr != nil {
panic(loadErr)
}
}