forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.go
44 lines (39 loc) · 929 Bytes
/
helper.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
35
36
37
38
39
40
41
42
43
44
package template
import (
"fmt"
"strings"
)
// TemplateReference points to a stored template
type TemplateReference struct {
Namespace string
Name string
}
// ParseTemplateReference parses the reference to a template into a
// TemplateReference.
func ParseTemplateReference(s string) (TemplateReference, error) {
var ref TemplateReference
parts := strings.Split(s, "/")
switch len(parts) {
case 2:
// namespace/name
ref.Namespace = parts[0]
ref.Name = parts[1]
break
case 1:
// name
ref.Name = parts[0]
break
default:
return ref, fmt.Errorf("the template reference must be either the template name or namespace and template name separated by slashes")
}
return ref, nil
}
func (r TemplateReference) HasNamespace() bool {
return len(r.Namespace) > 0
}
func (r TemplateReference) String() string {
if r.HasNamespace() {
return fmt.Sprintf("%s/%s", r.Namespace, r.Name)
}
return r.Name
}