42 lines
885 B
Go
42 lines
885 B
Go
|
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
|
||
|
}
|