mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-06 22:57:02 +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.4 KiB
Go
51 lines
1.4 KiB
Go
// Code generated by "enumer -type=generateRootKind -trimprefix=generateRoot"; DO NOT EDIT.
|
|
|
|
package command
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _generateRootKindName = "RegularDRRecovery"
|
|
|
|
var _generateRootKindIndex = [...]uint8{0, 7, 9, 17}
|
|
|
|
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:17]: 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
|
|
}
|