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

73 lines
1.5 KiB
Go

// Code generated by "enumer -type=Family -linecomment -text"; DO NOT EDIT.
//
package nethelpers
import (
"fmt"
)
const (
_FamilyName_0 = "inet4"
_FamilyName_1 = "inet6"
)
var (
_FamilyIndex_0 = [...]uint8{0, 5}
_FamilyIndex_1 = [...]uint8{0, 5}
)
func (i Family) String() string {
switch {
case i == 2:
return _FamilyName_0
case i == 10:
return _FamilyName_1
default:
return fmt.Sprintf("Family(%d)", i)
}
}
var _FamilyValues = []Family{2, 10}
var _FamilyNameToValueMap = map[string]Family{
_FamilyName_0[0:5]: 2,
_FamilyName_1[0:5]: 10,
}
// FamilyString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func FamilyString(s string) (Family, error) {
if val, ok := _FamilyNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Family values", s)
}
// FamilyValues returns all values of the enum
func FamilyValues() []Family {
return _FamilyValues
}
// IsAFamily returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Family) IsAFamily() bool {
for _, v := range _FamilyValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Family
func (i Family) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Family
func (i *Family) UnmarshalText(text []byte) error {
var err error
*i, err = FamilyString(string(text))
return err
}