-
Notifications
You must be signed in to change notification settings - Fork 19
/
key.go
34 lines (26 loc) · 845 Bytes
/
key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package runtime
import (
"fmt"
)
// Key represents storable object key - namespace + kind + name separated by KeySeparator
type Key = string
// KeySeparator is used to separate key parts (namespace, kind, name)
const KeySeparator = "/"
// KeyFromParts returns Key build using provided parts (namespace, kind, name)
func KeyFromParts(namespace string, kind Kind, name string) Key {
if len(namespace) == 0 {
panic(fmt.Sprintf("Key couldn't be created with empty namespace"))
}
if len(kind) == 0 {
panic(fmt.Sprintf("Key couldn't be created with empty kind"))
}
key := namespace + KeySeparator + kind
if len(name) > 0 {
key += KeySeparator + name
}
return key
}
// KeyForStorable returns Key for storable object
func KeyForStorable(obj Storable) Key {
return KeyFromParts(obj.GetNamespace(), obj.GetKind(), obj.GetName())
}