-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
45 lines (36 loc) · 902 Bytes
/
endpoint.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
package edgecenter
import (
"os"
"strconv"
edgecloud "github.com/Edge-Center/edgecentercloud-go"
)
var nilEndpointOptions = edgecloud.EndpointOpts{}
func EndpointOptionsFromEnv() (edgecloud.EndpointOpts, error) {
region := os.Getenv("EC_CLOUD_REGION")
project := os.Getenv("EC_CLOUD_PROJECT")
if region == "" {
err := edgecloud.MissingEnvironmentVariableError{
EnvironmentVariable: "EC_CLOUD_REGION",
}
return nilEndpointOptions, err
}
regionInt, err := strconv.Atoi(region)
if err != nil {
return nilEndpointOptions, err
}
if project == "" {
err := edgecloud.MissingEnvironmentVariableError{
EnvironmentVariable: "EC_CLOUD_PROJECT",
}
return nilEndpointOptions, err
}
projectInt, err := strconv.Atoi(project)
if err != nil {
return nilEndpointOptions, err
}
eo := edgecloud.EndpointOpts{
Region: regionInt,
Project: projectInt,
}
return eo, nil
}