mirror of
https://github.com/hamburghammer/gmon.git
synced 2024-05-03 22:55:25 +02:00
Augusto Dwenger J.
bf8304f02c
Go does not allow the usage of an interface on a typed array. To resolve this issue we manually create a new array with the interface type and add all items to it. This no happens inside the rules sturct instead of being a single standalone function inside the main package.
46 lines
969 B
Go
46 lines
969 B
Go
package config
|
|
|
|
import "github.com/hamburghammer/gmon/analyse"
|
|
|
|
// RulesLoader is the interface that should be implemented if you want to load rules.
|
|
type RulesLoader interface {
|
|
Load() (Rules, error)
|
|
}
|
|
|
|
// Rules holds all configured rules.
|
|
type Rules struct {
|
|
CPU []analyse.CPURule
|
|
Disk []analyse.DiskRule
|
|
RAM []analyse.RAMRule
|
|
}
|
|
|
|
// GetCPU returns the cpu rules as analyser interface
|
|
func (r Rules) GetCPU() []analyse.Analyser {
|
|
rules := make([]analyse.Analyser, len(r.CPU))
|
|
for i, r := range r.CPU {
|
|
rules[i] = r
|
|
}
|
|
|
|
return rules
|
|
}
|
|
|
|
// GetDisk returns the disk rules as analyser interface
|
|
func (r Rules) GetDisk() []analyse.Analyser {
|
|
rules := make([]analyse.Analyser, len(r.Disk))
|
|
for i, r := range r.Disk {
|
|
rules[i] = r
|
|
}
|
|
|
|
return rules
|
|
}
|
|
|
|
// GetRAM returns the ram rules as analyser interface
|
|
func (r Rules) GetRAM() []analyse.Analyser {
|
|
rules := make([]analyse.Analyser, len(r.RAM))
|
|
for i, r := range r.RAM {
|
|
rules[i] = r
|
|
}
|
|
|
|
return rules
|
|
}
|