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

81 lines
1.8 KiB
Go

// Code generated by "enumer -type=Scope -linecomment -text"; DO NOT EDIT.
//
package nethelpers
import (
"fmt"
)
const (
_ScopeName_0 = "global"
_ScopeName_1 = "site"
_ScopeName_2 = "linkhostnowhere"
)
var (
_ScopeIndex_0 = [...]uint8{0, 6}
_ScopeIndex_1 = [...]uint8{0, 4}
_ScopeIndex_2 = [...]uint8{0, 4, 8, 15}
)
func (i Scope) String() string {
switch {
case i == 0:
return _ScopeName_0
case i == 200:
return _ScopeName_1
case 253 <= i && i <= 255:
i -= 253
return _ScopeName_2[_ScopeIndex_2[i]:_ScopeIndex_2[i+1]]
default:
return fmt.Sprintf("Scope(%d)", i)
}
}
var _ScopeValues = []Scope{0, 200, 253, 254, 255}
var _ScopeNameToValueMap = map[string]Scope{
_ScopeName_0[0:6]: 0,
_ScopeName_1[0:4]: 200,
_ScopeName_2[0:4]: 253,
_ScopeName_2[4:8]: 254,
_ScopeName_2[8:15]: 255,
}
// ScopeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func ScopeString(s string) (Scope, error) {
if val, ok := _ScopeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Scope values", s)
}
// ScopeValues returns all values of the enum
func ScopeValues() []Scope {
return _ScopeValues
}
// IsAScope returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Scope) IsAScope() bool {
for _, v := range _ScopeValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Scope
func (i Scope) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Scope
func (i *Scope) UnmarshalText(text []byte) error {
var err error
*i, err = ScopeString(string(text))
return err
}