-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.go
44 lines (34 loc) · 871 Bytes
/
environment.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
package appy
import (
"errors"
"fmt"
"os"
"github.com/joho/godotenv"
)
// Various settings for the environment in appy
type EnvironmentSettings struct {
// If true then appy instructs its providers to run in debug mode
DebugMode bool
}
var environmentSettings EnvironmentSettings = EnvironmentSettings{
DebugMode: false,
}
// Get the current environment settings for appy
func Environment() *EnvironmentSettings {
return &environmentSettings
}
// LoadFromFile loads the environment settings from a file
func (es *EnvironmentSettings) LoadFromFile(file string) error {
err := godotenv.Load(file)
if err != nil {
return err
}
return nil
}
func (es *EnvironmentSettings) GetValue(key string) (string, error) {
val := os.Getenv(key)
if val == "" {
return "", errors.New(fmt.Sprintf("environment variable '%s' not set", key))
}
return val, nil
}