uplink/app/transcoders/options/transcoder_option_tree.go

42 lines
885 B
Go
Raw Normal View History

2018-04-10 11:48:51 +00:00
package options
import "errors"
type TranscoderOptionTree struct {
optionTypes map[string]TranscoderOptionType
}
func (tree *TranscoderOptionTree) GenerateDefaultValues() (retval map[string]interface{}) {
retval = map[string]interface{}{}
for key, optionType := range tree.optionTypes {
retval[key] = optionType.Default()
}
return
}
func (tree *TranscoderOptionTree) ValidateValues(values map[string]interface{}) (errs map[string]error) {
for key, optionType := range tree.optionTypes {
value, ok := tree.optionTypes[key]
if !ok {
if optionType.IsRequired() {
errs[key] = errors.New("missing required option")
}
continue
}
if err := optionType.Validate(value); err != nil {
errs[key] = err
}
}
for key := range values {
_, ok := tree.optionTypes[key]
if !ok {
errs[key] = errors.New("unrecognized option")
continue
}
}
return
}