mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-23 23:51:08 +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.2 KiB
Go
51 lines
1.2 KiB
Go
// Code generated by "enumer -type=CaseOp -transform=snake"; DO NOT EDIT.
|
|
|
|
package credsutil
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const _CaseOpName = "keep_caseuppercaselowercase"
|
|
|
|
var _CaseOpIndex = [...]uint8{0, 9, 18, 27}
|
|
|
|
func (i CaseOp) String() string {
|
|
if i < 0 || i >= CaseOp(len(_CaseOpIndex)-1) {
|
|
return fmt.Sprintf("CaseOp(%d)", i)
|
|
}
|
|
return _CaseOpName[_CaseOpIndex[i]:_CaseOpIndex[i+1]]
|
|
}
|
|
|
|
var _CaseOpValues = []CaseOp{0, 1, 2}
|
|
|
|
var _CaseOpNameToValueMap = map[string]CaseOp{
|
|
_CaseOpName[0:9]: 0,
|
|
_CaseOpName[9:18]: 1,
|
|
_CaseOpName[18:27]: 2,
|
|
}
|
|
|
|
// CaseOpString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func CaseOpString(s string) (CaseOp, error) {
|
|
if val, ok := _CaseOpNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to CaseOp values", s)
|
|
}
|
|
|
|
// CaseOpValues returns all values of the enum
|
|
func CaseOpValues() []CaseOp {
|
|
return _CaseOpValues
|
|
}
|
|
|
|
// IsACaseOp returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i CaseOp) IsACaseOp() bool {
|
|
for _, v := range _CaseOpValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|