/
baseline.go
33 lines (30 loc) · 938 Bytes
/
baseline.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
package watched
import (
"fmt"
"os"
)
// Baseline is the type of a baseline workload. We use
// this instead of the grpc routes.Baseline because it
// can be used as a map key, whereas the grpc one cannot.
type Baseline struct {
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Name string `json:"name"`
}
// BaselineFromEnv grabs the baseline from the environment
// if possible. Otherwise, it returns nil and a non-nil error.
func BaselineFromEnv() (*Baseline, error) {
k := os.Getenv(BaselineKindEnvVar)
if k == "" {
return nil, fmt.Errorf("%s not found in env", BaselineKindEnvVar)
}
ns := os.Getenv(BaselineNamespaceEnvVar)
if ns == "" {
return nil, fmt.Errorf("%s not found in env", BaselineNamespaceEnvVar)
}
n := os.Getenv(BaselineNameEnvVar)
if n == "" {
return nil, fmt.Errorf("%s not found in env", BaselineNameEnvVar)
}
return &Baseline{Kind: k, Namespace: ns, Name: n}, nil
}