feat(resource): Add function to get type from plural string
This commit is contained in:
1 file changed
+14
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user