-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
62 lines (50 loc) · 1.02 KB
/
types.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
package main
import "fmt"
// ScriptType of what type of script it is
type ScriptType int
// Startup / Shutdown constant for that of a startup script
const (
Startup ScriptType = iota + 1
Shutdown
)
func (t ScriptType) String() string {
types := [...]string{
"startup",
"shutdown",
}
if t < Startup || t > Shutdown {
return "unknown"
}
return types[t-1]
}
// ParseScriptType will take the type of script string and map to the ScriptType constant
func ParseScriptType(s string) (ScriptType, error) {
var ret ScriptType
switch s {
case "startup":
ret = Startup
break
case "shutdown":
ret = Shutdown
break
}
// unknown script type
if ret > 0 {
return ret, nil
}
return 0, fmt.Errorf("unknown script type")
}
// Startup will return true if it's time for a startup script
func (t ScriptType) Startup() bool {
if t == Startup {
return true
}
return false
}
// Shutdown will return true if it's shutdown script time
func (t ScriptType) Shutdown() bool {
if t == Shutdown {
return true
}
return false
}