package handlerfactory import ( "gopkg.in/yaml.v2" "io" "io/ioutil" "strings" ) type FactoryConfig struct { Mode FCMOde `yaml:"mode"` Target string `yaml:"target"` SceneNames []string `yaml:"scenes"` TriggerDeviceID string `yaml:"trigger_device_id"` } type FCMOde string var ( SceneDimmer FCMOde = "SceneDimmer" ) func ParseConfigs(reader io.Reader) ([]FactoryConfig, error) { readAll, err := ioutil.ReadAll(reader) if err != nil { return nil, err } splits := strings.Split(string(readAll), "\n---\n") configs := make([]FactoryConfig, 0, 8) for _, split := range splits { var factoryConfig FactoryConfig err := yaml.NewDecoder(strings.NewReader(split)).Decode(&factoryConfig) if err != nil { return nil, err } configs = append(configs, factoryConfig) } return configs, nil }