/
app_meta.go
46 lines (35 loc) · 935 Bytes
/
app_meta.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
package app
import (
"encoding/json"
"fmt"
)
type AppMeta struct {
LabelKey string `json:"labelKey"`
LabelValue string `json:"labelValue"`
LastChangeName string `json:"lastChangeName,omitempty"`
LastChange ChangeMeta `json:"lastChange,omitempty"`
}
func NewAppMetaFromString(data string) AppMeta {
var meta AppMeta
err := json.Unmarshal([]byte(data), &meta)
if err != nil {
panic(fmt.Sprintf("Decoding app meta: %s", err))
}
return meta
}
func NewAppMetaFromData(data map[string]string) AppMeta {
return NewAppMetaFromString(data["spec"])
}
func (m AppMeta) AsString() string {
bytes, err := json.Marshal(m)
if err != nil {
panic(fmt.Sprintf("Encoding app meta: %s", err))
}
return string(bytes)
}
func (m AppMeta) AsData() map[string]string {
return map[string]string{"spec": m.AsString()}
}
func (m AppMeta) Labels() map[string]string {
return map[string]string{m.LabelKey: m.LabelValue}
}