2022-04-13 07:48:22 +00:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Results []Result
|
|
|
|
|
|
|
|
type Result struct {
|
2022-04-13 23:09:58 +00:00
|
|
|
Id int `yaml:"Itemid"`
|
|
|
|
Name string `yaml:"Name"`
|
|
|
|
Rate float64 `yaml:"Rate"`
|
2022-04-13 07:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewResultsFromFile(path string) (Results, error) {
|
|
|
|
out := []Result{}
|
|
|
|
bts, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(bts, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|