Make enum values typed strings (#18)
This also moves validation into the parsing process and refactors a bunch of code related to the config. Reviewed-on: #18 Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
8d2b15a7c8
commit
8a903e0703
10 changed files with 232 additions and 173 deletions
35
internal/configparser/deviceconfigphysical.go
Normal file
35
internal/configparser/deviceconfigphysical.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package configparser
|
||||
|
||||
type DeviceConfigPhysical struct {
|
||||
Name string
|
||||
DeviceName string `yaml:"device_name,omitempty"`
|
||||
DevicePath string `yaml:"device_path,omitempty"`
|
||||
Lock bool
|
||||
}
|
||||
|
||||
// TODO: custom yaml unmarshaling is obtuse; do we really need to do all of this work
|
||||
// just to set a single default value?
|
||||
func (dc *DeviceConfigPhysical) UnmarshalYAML(unmarshal func(data interface{}) error) error {
|
||||
var raw struct {
|
||||
Name string
|
||||
DeviceName string `yaml:"device_name"`
|
||||
DevicePath string `yaml:"device_path"`
|
||||
Lock bool `yaml:"lock,omitempty"`
|
||||
}
|
||||
|
||||
// Set non-standard defaults
|
||||
raw.Lock = true
|
||||
|
||||
err := unmarshal(&raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*dc = DeviceConfigPhysical{
|
||||
Name: raw.Name,
|
||||
DeviceName: raw.DeviceName,
|
||||
DevicePath: raw.DevicePath,
|
||||
Lock: raw.Lock,
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue