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

This commit is contained in:
Timothy Messier committed 2023-12-04 16:20:44 +00:00
1 parent bc48e58035
commit 61fcd857ec
1 file changed
+14 -1
+14 -1
View File
@@ -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,