This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_types.go
95 lines (78 loc) · 1.82 KB
/
template_types.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
// Service represents a Rancher service.
type Service struct {
Name string
Stack string
Kind string // service, loadBalancerService
Vip string
Fqdn string
Ports []ServicePort
Labels LabelMap
Metadata MetadataMap
Containers []Container
}
// Container represents a container belonging to a Rancher Service.
type Container struct {
Name string
Address string
Stack string
Service string
Health string
State string
Labels LabelMap
Host Host
}
// Host represents a Rancher Host.
type Host struct {
UUID string
Name string
Address string
Hostname string
Labels LabelMap
}
// Self contains information about the container running this application.
type Self struct {
Stack string
Service string
HostUUID string
}
// ServicePort represents a port exposed by a service
type ServicePort struct {
PublicPort string
InternalPort string
Protocol string
}
// LabelMap contains the labels of a service or host.
type LabelMap map[string]string
// Exists returns true if the Labels contain the given key.
func (l LabelMap) Exists(key string) bool {
_, ok := l[key]
return ok
}
// Value returns the value of the given label key.
func (l LabelMap) GetValue(key string, v ...string) string {
if val, ok := l[key]; ok && len(val) > 0 {
return val
}
if len(v) > 0 {
return v[0]
}
return ""
}
// MetadataMap contains the metadata of a service.
type MetadataMap map[string]interface{}
// Exists returns true if the metadata contains the given key.
func (m MetadataMap) Exists(key string) bool {
_, ok := m[key]
return ok
}
// Value returns the value of the given metadata key.
func (m MetadataMap) GetValue(key string, v ...interface{}) interface{} {
if val, ok := m[key]; ok {
return val
}
if len(v) > 0 {
return v[0]
}
return ""
}