-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_env.go
65 lines (49 loc) · 1.24 KB
/
config_env.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
57
58
59
60
61
62
63
64
65
package entities
import "errors"
func (c *Config) SetEnv(clusterName string, env *Env) error {
if !c.ClusterExists(clusterName) {
return ErrClusterNotExists{
ClusterName: clusterName,
}
}
if env == nil {
return errors.New("passed env is nil")
}
c.Clusters[clusterName].Envs[env.Name] = env
return nil
}
func (c *Config) EnvExists(clusterName, envName string) bool {
if !c.ClusterExists(clusterName) {
return false
}
_, envExists := c.Clusters[clusterName].Envs[envName]
return envExists
}
func (c *Config) GetEnv(clusterName, envName string) (*Env, error) {
if !c.EnvExists(clusterName, envName) {
return nil, ErrEnvNotExists{
ClusterName: clusterName,
EnvName: envName,
}
}
env := c.Clusters[clusterName].Envs[envName]
return env, nil
}
func (c *Config) RemoveEnv(clusterName, envName string) error {
if !c.EnvExists(clusterName, envName) {
return ErrEnvNotExists{
ClusterName: clusterName,
EnvName: envName,
}
}
delete(c.Clusters[clusterName].Envs, envName)
return nil
}
func (c *Config) CountEnvsInCluster(clusterName string) (int, error) {
if !c.ClusterExists(clusterName) {
return 0, ErrClusterNotExists{
ClusterName: clusterName,
}
}
return len(c.Clusters[clusterName].Envs), nil
}