-
Notifications
You must be signed in to change notification settings - Fork 90
/
spec.go
41 lines (37 loc) · 892 Bytes
/
spec.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 spec
import (
"github.com/mackerelio/golib/logging"
"github.com/mackerelio/mackerel-client-go"
)
var logger = logging.GetLogger("spec")
// Generator interface for generating spec values
type Generator interface {
Generate() (any, error)
}
// Collect spec values
func Collect(specGenerators []Generator) mackerel.HostMeta {
var specs mackerel.HostMeta
for _, g := range specGenerators {
value, err := g.Generate()
if err != nil {
logger.Warningf("Failed to collect meta in %T (skip this spec): %s", g, err.Error())
continue
}
switch v := value.(type) {
case mackerel.BlockDevice:
specs.BlockDevice = v
case mackerel.CPU:
specs.CPU = v
case mackerel.FileSystem:
specs.Filesystem = v
case mackerel.Kernel:
specs.Kernel = v
case mackerel.Memory:
specs.Memory = v
case *mackerel.Cloud:
specs.Cloud = v
default:
}
}
return specs
}