forked from kyma-project/kyma
/
config.go
executable file
·47 lines (38 loc) · 1.06 KB
/
config.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
package testkit
import (
"errors"
"fmt"
"log"
"os"
)
const (
internalAPIUrlEnvName = "INTERNAL_API_URL"
externalAPIUrlEnvName = "EXTERNAL_API_URL"
gatewayUrlEnvName = "GATEWAY_URL"
)
type TestConfig struct {
InternalAPIUrl string
ExternalAPIUrl string
GatewayUrl string
}
func ReadConfig() (TestConfig, error) {
internalAPIUrl, found := os.LookupEnv(internalAPIUrlEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", internalAPIUrlEnvName))
}
externalAPIUrl, found := os.LookupEnv(externalAPIUrlEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", externalAPIUrlEnvName))
}
gatewayUrl, found := os.LookupEnv(gatewayUrlEnvName)
if !found {
return TestConfig{}, errors.New(fmt.Sprintf("failed to read %s environment variable", gatewayUrlEnvName))
}
config := TestConfig{
InternalAPIUrl: internalAPIUrl,
ExternalAPIUrl: externalAPIUrl,
GatewayUrl: gatewayUrl,
}
log.Printf("Read configuration: %+v", config)
return config, nil
}