feat(resource): Add function to get type from plural string

pull/4093/head
Timothy Messier 3 years ago
parent bc48e58035
commit 61fcd857ec
No known key found for this signature in database
GPG Key ID: EFD2F184F7600572

@ -3,7 +3,10 @@
package resource
import "encoding/json"
import (
"encoding/json"
"strings"
)
// Type defines the types of resources in the system
type Type uint
@ -81,6 +84,16 @@ func (r Type) PluralString() string {
}
}
func FromPlural(s string) (Type, bool) {
switch s {
case "credential-libraries":
return CredentialLibrary, true
default:
t, ok := Map[strings.TrimSuffix(s, "s")]
return t, ok
}
}
var Map = map[string]Type{
Unknown.String(): Unknown,
All.String(): All,

Loading…
Cancel
Save