joyful/internal/configparser/deviceconfigphysical.go
Anna Rose Wiggins 8a903e0703 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>
2025-09-05 21:17:55 +00:00

35 lines
843 B
Go

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
}