-
Notifications
You must be signed in to change notification settings - Fork 224
/
platformversion.go
54 lines (47 loc) · 1.45 KB
/
platformversion.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
package appconfig
import "fmt"
func (c *Config) EnsureV2Config() error {
return c.v2UnmarshalError
}
// SetMachinesPlatform informs the TOML marshaller that this config is for the machines platform
func (c *Config) SetMachinesPlatform() error {
if c.v2UnmarshalError != nil {
return c.v2UnmarshalError
}
c.platformVersion = MachinesPlatform
return nil
}
// SetMachinesPlatform informs the TOML marshaller that this config is for the machines platform
func (c *Config) SetDetachedPlatform() error {
if c.v2UnmarshalError != nil {
return c.v2UnmarshalError
}
c.platformVersion = DetachedPlatform
return nil
}
// SetNomadPlatform informs the TOML marshaller that this config is for the nomad platform
func (c *Config) SetNomadPlatform() error {
if len(c.RawDefinition) == 0 {
return fmt.Errorf("Can't set platformVersion to Nomad on an empty RawDefinition")
}
c.platformVersion = NomadPlatform
return nil
}
func (c *Config) SetPlatformVersion(platform string) error {
switch platform {
case MachinesPlatform:
return c.SetMachinesPlatform()
case NomadPlatform:
return c.SetNomadPlatform()
case DetachedPlatform:
return c.SetDetachedPlatform()
case "":
return fmt.Errorf("Empty value as platform version")
default:
return fmt.Errorf("Unknown platform version: '%s'", platform)
}
}
// ForMachines is true when the config is intended for the machines platform
func (c *Config) ForMachines() bool {
return c.platformVersion == MachinesPlatform
}