mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 08:37:00 +02:00
We have many hand-written String() methods (and similar) for enums. These require more maintenance and are more error-prone than using automatically generated methods. In addition, the auto-generated versions can be more efficient. Here, we switch to using https://github.com/loggerhead/enumer, itself a fork of https://github.com/diegostamigni/enumer, no longer maintained, and a fork of the mostly standard tool https://pkg.go.dev/golang.org/x/tools/cmd/stringer. We use this fork of enumer for Go 1.20+ compatibility and because we require the `-transform` flag to be able to generate constants that match our current code base. Some enums were not targeted for this change:
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
// Code generated by "enumer -type=GenerateRootKind -trimprefix=GenerateRoot"; DO NOT EDIT.
|
|
|
|
package testcluster
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _GenerateRootKindName = "RegularDRGenerateRecovery"
|
|
|
|
var _GenerateRootKindIndex = [...]uint8{0, 7, 9, 25}
|
|
|
|
func (i GenerateRootKind) String() string {
|
|
if i < 0 || i >= GenerateRootKind(len(_GenerateRootKindIndex)-1) {
|
|
return fmt.Sprintf("GenerateRootKind(%d)", i)
|
|
}
|
|
return _GenerateRootKindName[_GenerateRootKindIndex[i]:_GenerateRootKindIndex[i+1]]
|
|
}
|
|
|
|
var _GenerateRootKindValues = []GenerateRootKind{0, 1, 2}
|
|
|
|
var _GenerateRootKindNameToValueMap = map[string]GenerateRootKind{
|
|
_GenerateRootKindName[0:7]: 0,
|
|
_GenerateRootKindName[7:9]: 1,
|
|
_GenerateRootKindName[9:25]: 2,
|
|
}
|
|
|
|
// GenerateRootKindString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func GenerateRootKindString(s string) (GenerateRootKind, error) {
|
|
if val, ok := _GenerateRootKindNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to GenerateRootKind values", s)
|
|
}
|
|
|
|
// GenerateRootKindValues returns all values of the enum
|
|
func GenerateRootKindValues() []GenerateRootKind {
|
|
return _GenerateRootKindValues
|
|
}
|
|
|
|
// IsAGenerateRootKind returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i GenerateRootKind) IsAGenerateRootKind() bool {
|
|
for _, v := range _GenerateRootKindValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|