-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
39 lines (32 loc) · 839 Bytes
/
host.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
package sdk
import (
"github.com/tliron/commonlog"
"gopkg.in/yaml.v3"
)
func (self *State) GetHost(name string) (*Host, error) {
var host Host
if reader, err := self.LockAndOpenPackageFile("common", "host", name, "host.yaml"); err == nil {
defer commonlog.CallAndLogError(reader.Close, "close", stateLog)
if err := yaml.NewDecoder(reader).Decode(&host); err == nil {
return &host, nil
} else {
return nil, err
}
} else {
return nil, err
}
}
func (self *State) SetHost(name string, host *Host) error {
if writer, err := self.LockAndCreatePackageFile("common", "host", name, "host.yaml"); err == nil {
defer commonlog.CallAndLogError(writer.Close, "close", stateLog)
return yaml.NewEncoder(writer).Encode(host)
} else {
return err
}
}
//
// Host
//
type Host struct {
Address string `yaml:"address"`
}