sampler-fork/config/data.go

32 lines
507 B
Go
Raw Normal View History

2019-01-25 04:10:38 +00:00
package config
import (
"log"
"os/exec"
"strconv"
"strings"
)
type Data struct {
2019-01-28 23:09:52 +00:00
Label string `yaml:"label"`
Color string `yaml:"color"`
2019-01-25 04:10:38 +00:00
Script string `yaml:"script"`
}
func (d *Data) NextValue() (float64, error) {
output, err := exec.Command("sh", "-c", d.Script).Output()
if err != nil {
log.Printf("%s", err)
}
trimmedOutput := strings.TrimSpace(string(output))
floatValue, err := strconv.ParseFloat(trimmedOutput, 64)
if err != nil {
return 0, err
}
return floatValue, nil
}