mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-07 15:17:03 +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:
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
// Code generated by "enumer -type=childProcessState -trimprefix=childProcessState"; DO NOT EDIT.
|
|
|
|
package exec
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _childProcessStateName = "NotStartedRunningRestartingStopped"
|
|
|
|
var _childProcessStateIndex = [...]uint8{0, 10, 17, 27, 34}
|
|
|
|
func (i childProcessState) String() string {
|
|
if i >= childProcessState(len(_childProcessStateIndex)-1) {
|
|
return fmt.Sprintf("childProcessState(%d)", i)
|
|
}
|
|
return _childProcessStateName[_childProcessStateIndex[i]:_childProcessStateIndex[i+1]]
|
|
}
|
|
|
|
var _childProcessStateValues = []childProcessState{0, 1, 2, 3}
|
|
|
|
var _childProcessStateNameToValueMap = map[string]childProcessState{
|
|
_childProcessStateName[0:10]: 0,
|
|
_childProcessStateName[10:17]: 1,
|
|
_childProcessStateName[17:27]: 2,
|
|
_childProcessStateName[27:34]: 3,
|
|
}
|
|
|
|
// childProcessStateString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func childProcessStateString(s string) (childProcessState, error) {
|
|
if val, ok := _childProcessStateNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to childProcessState values", s)
|
|
}
|
|
|
|
// childProcessStateValues returns all values of the enum
|
|
func childProcessStateValues() []childProcessState {
|
|
return _childProcessStateValues
|
|
}
|
|
|
|
// IsAchildProcessState returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i childProcessState) IsAchildProcessState() bool {
|
|
for _, v := range _childProcessStateValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|