mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 00:27: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:
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
// Code generated by "enumer -type=tidyStatusState -trimprefix=tidyStatus"; DO NOT EDIT.
|
|
|
|
package pki
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _tidyStatusStateName = "InactiveStartedFinishedErrorCancellingCancelled"
|
|
|
|
var _tidyStatusStateIndex = [...]uint8{0, 8, 15, 23, 28, 38, 47}
|
|
|
|
func (i tidyStatusState) String() string {
|
|
if i < 0 || i >= tidyStatusState(len(_tidyStatusStateIndex)-1) {
|
|
return fmt.Sprintf("tidyStatusState(%d)", i)
|
|
}
|
|
return _tidyStatusStateName[_tidyStatusStateIndex[i]:_tidyStatusStateIndex[i+1]]
|
|
}
|
|
|
|
var _tidyStatusStateValues = []tidyStatusState{0, 1, 2, 3, 4, 5}
|
|
|
|
var _tidyStatusStateNameToValueMap = map[string]tidyStatusState{
|
|
_tidyStatusStateName[0:8]: 0,
|
|
_tidyStatusStateName[8:15]: 1,
|
|
_tidyStatusStateName[15:23]: 2,
|
|
_tidyStatusStateName[23:28]: 3,
|
|
_tidyStatusStateName[28:38]: 4,
|
|
_tidyStatusStateName[38:47]: 5,
|
|
}
|
|
|
|
// tidyStatusStateString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func tidyStatusStateString(s string) (tidyStatusState, error) {
|
|
if val, ok := _tidyStatusStateNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to tidyStatusState values", s)
|
|
}
|
|
|
|
// tidyStatusStateValues returns all values of the enum
|
|
func tidyStatusStateValues() []tidyStatusState {
|
|
return _tidyStatusStateValues
|
|
}
|
|
|
|
// IsAtidyStatusState returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i tidyStatusState) IsAtidyStatusState() bool {
|
|
for _, v := range _tidyStatusStateValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|