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

76 lines
1.9 KiB
Go

// Code generated by "enumer -type=RoutingTable -linecomment -text"; DO NOT EDIT.
//
package nethelpers
import (
"fmt"
)
const (
_RoutingTableName_0 = "unspec"
_RoutingTableName_1 = "defaultmainlocal"
)
var (
_RoutingTableIndex_0 = [...]uint8{0, 6}
_RoutingTableIndex_1 = [...]uint8{0, 7, 11, 16}
)
func (i RoutingTable) String() string {
switch {
case i == 0:
return _RoutingTableName_0
case 253 <= i && i <= 255:
i -= 253
return _RoutingTableName_1[_RoutingTableIndex_1[i]:_RoutingTableIndex_1[i+1]]
default:
return fmt.Sprintf("RoutingTable(%d)", i)
}
}
var _RoutingTableValues = []RoutingTable{0, 253, 254, 255}
var _RoutingTableNameToValueMap = map[string]RoutingTable{
_RoutingTableName_0[0:6]: 0,
_RoutingTableName_1[0:7]: 253,
_RoutingTableName_1[7:11]: 254,
_RoutingTableName_1[11:16]: 255,
}
// RoutingTableString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func RoutingTableString(s string) (RoutingTable, error) {
if val, ok := _RoutingTableNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to RoutingTable values", s)
}
// RoutingTableValues returns all values of the enum
func RoutingTableValues() []RoutingTable {
return _RoutingTableValues
}
// IsARoutingTable returns "true" if the value is listed in the enum definition. "false" otherwise
func (i RoutingTable) IsARoutingTable() bool {
for _, v := range _RoutingTableValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for RoutingTable
func (i RoutingTable) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for RoutingTable
func (i *RoutingTable) UnmarshalText(text []byte) error {
var err error
*i, err = RoutingTableString(string(text))
return err
}