Use typed enums for cleaner parsing.
This commit is contained in:
parent
8d2b15a7c8
commit
553966ac87
5 changed files with 33 additions and 40 deletions
|
@ -15,12 +15,12 @@ type Config struct {
|
|||
|
||||
// These top-level structs use custom unmarshaling to unpack each available sub-type
|
||||
type DeviceConfig struct {
|
||||
Type string
|
||||
Type DeviceType
|
||||
Config interface{}
|
||||
}
|
||||
|
||||
type RuleConfig struct {
|
||||
Type string
|
||||
Type RuleType
|
||||
Name string
|
||||
Modes []string
|
||||
Config interface{}
|
||||
|
@ -119,7 +119,7 @@ type RuleTargetConfigModeSelect struct {
|
|||
|
||||
func (dc *DeviceConfig) UnmarshalYAML(unmarshal func(data interface{}) error) error {
|
||||
metaConfig := &struct {
|
||||
Type string
|
||||
Type DeviceType
|
||||
}{}
|
||||
err := unmarshal(metaConfig)
|
||||
if err != nil {
|
||||
|
@ -145,7 +145,7 @@ func (dc *DeviceConfig) UnmarshalYAML(unmarshal func(data interface{}) error) er
|
|||
|
||||
func (dc *RuleConfig) UnmarshalYAML(unmarshal func(data interface{}) error) error {
|
||||
metaConfig := &struct {
|
||||
Type string
|
||||
Type RuleType
|
||||
Name string
|
||||
Modes []string
|
||||
}{}
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package configparser
|
||||
|
||||
const (
|
||||
DeviceTypePhysical = "physical"
|
||||
DeviceTypeVirtual = "virtual"
|
||||
type DeviceType string
|
||||
|
||||
RuleTypeButton = "button"
|
||||
RuleTypeButtonCombo = "button-combo"
|
||||
RuleTypeButtonLatched = "button-latched"
|
||||
RuleTypeAxis = "axis"
|
||||
RuleTypeAxisCombined = "axis-combined"
|
||||
RuleTypeAxisToButton = "axis-to-button"
|
||||
RuleTypeAxisToRelaxis = "axis-to-relaxis"
|
||||
RuleTypeModeSelect = "mode-select"
|
||||
const (
|
||||
DeviceTypePhysical DeviceType = "physical"
|
||||
DeviceTypeVirtual DeviceType = "virtual"
|
||||
)
|
||||
|
||||
type RuleType string
|
||||
|
||||
const (
|
||||
RuleTypeButton RuleType = "button"
|
||||
RuleTypeButtonCombo RuleType = "button-combo"
|
||||
RuleTypeButtonLatched RuleType = "button-latched"
|
||||
RuleTypeAxis RuleType = "axis"
|
||||
RuleTypeAxisCombined RuleType = "axis-combined"
|
||||
RuleTypeAxisToButton RuleType = "axis-to-button"
|
||||
RuleTypeAxisToRelaxis RuleType = "axis-to-relaxis"
|
||||
RuleTypeModeSelect RuleType = "mode-select"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue