talos/pkg/machinery/resources/network/configlayer_enumer.go
Andrey Smirnov d02d944ec7
chore: provide umarshal from YAML methods for network resource specs
This will be required to preserve platform network configuration in a
cache across boots. Network configuration will be marshaled to YAML and
unmarshaled back.

Changes are pretty simple and most of the code is auto-generated:
replace `stringer` codegen with `enumer` which produces also methods
which convert from string back to enum values.

Added tests to verify YAML marshaling/unmarshaling.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-01-10 17:00:53 +03:00

66 lines
1.8 KiB
Go

// Code generated by "enumer -type=ConfigLayer -linecomment -text"; DO NOT EDIT.
//
package network
import (
"fmt"
)
const _ConfigLayerName = "defaultcmdlineplatformoperatorconfiguration"
var _ConfigLayerIndex = [...]uint8{0, 7, 14, 22, 30, 43}
func (i ConfigLayer) String() string {
if i < 0 || i >= ConfigLayer(len(_ConfigLayerIndex)-1) {
return fmt.Sprintf("ConfigLayer(%d)", i)
}
return _ConfigLayerName[_ConfigLayerIndex[i]:_ConfigLayerIndex[i+1]]
}
var _ConfigLayerValues = []ConfigLayer{0, 1, 2, 3, 4}
var _ConfigLayerNameToValueMap = map[string]ConfigLayer{
_ConfigLayerName[0:7]: 0,
_ConfigLayerName[7:14]: 1,
_ConfigLayerName[14:22]: 2,
_ConfigLayerName[22:30]: 3,
_ConfigLayerName[30:43]: 4,
}
// ConfigLayerString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ConfigLayerString(s string) (ConfigLayer, error) {
if val, ok := _ConfigLayerNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to ConfigLayer values", s)
}
// ConfigLayerValues returns all values of the enum
func ConfigLayerValues() []ConfigLayer {
return _ConfigLayerValues
}
// IsAConfigLayer returns "true" if the value is listed in the enum definition. "false" otherwise
func (i ConfigLayer) IsAConfigLayer() bool {
for _, v := range _ConfigLayerValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for ConfigLayer
func (i ConfigLayer) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for ConfigLayer
func (i *ConfigLayer) UnmarshalText(text []byte) error {
var err error
*i, err = ConfigLayerString(string(text))
return err
}