/
unit.go
41 lines (33 loc) · 725 Bytes
/
unit.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
package unit
import (
unit "github.com/cogolabs/fleet2kubes/pkg/fleet-unit"
)
type Unit struct {
*unit.UnitFile
RunFlags map[string]string
RunImage string
RunCommand []string
Network map[string]string
Macros map[string]string
Env map[string]string
}
func NewUnit(raw string) (*Unit, error) {
uf, err := unit.NewUnitFile(raw)
if err != nil {
return nil, err
}
u := &Unit{UnitFile: uf}
u.Network = u.parseNetwork()
u.RunImage, u.RunCommand, u.RunFlags, u.Env = u.parseExecStart()
return u, nil
}
func (u *Unit) FirstValue(section, name string) string {
if u == nil || u.Options == nil {
return ""
}
values := u.Contents[section][name]
if len(values) == 0 {
return ""
}
return values[0]
}