talos/pkg/machinery/nethelpers/primaryreselect_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

64 lines
1.8 KiB
Go

// Code generated by "enumer -type=PrimaryReselect -linecomment -text"; DO NOT EDIT.
//
package nethelpers
import (
"fmt"
)
const _PrimaryReselectName = "alwaysbetterfailure"
var _PrimaryReselectIndex = [...]uint8{0, 6, 12, 19}
func (i PrimaryReselect) String() string {
if i >= PrimaryReselect(len(_PrimaryReselectIndex)-1) {
return fmt.Sprintf("PrimaryReselect(%d)", i)
}
return _PrimaryReselectName[_PrimaryReselectIndex[i]:_PrimaryReselectIndex[i+1]]
}
var _PrimaryReselectValues = []PrimaryReselect{0, 1, 2}
var _PrimaryReselectNameToValueMap = map[string]PrimaryReselect{
_PrimaryReselectName[0:6]: 0,
_PrimaryReselectName[6:12]: 1,
_PrimaryReselectName[12:19]: 2,
}
// PrimaryReselectString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func PrimaryReselectString(s string) (PrimaryReselect, error) {
if val, ok := _PrimaryReselectNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to PrimaryReselect values", s)
}
// PrimaryReselectValues returns all values of the enum
func PrimaryReselectValues() []PrimaryReselect {
return _PrimaryReselectValues
}
// IsAPrimaryReselect returns "true" if the value is listed in the enum definition. "false" otherwise
func (i PrimaryReselect) IsAPrimaryReselect() bool {
for _, v := range _PrimaryReselectValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for PrimaryReselect
func (i PrimaryReselect) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for PrimaryReselect
func (i *PrimaryReselect) UnmarshalText(text []byte) error {
var err error
*i, err = PrimaryReselectString(string(text))
return err
}