-
Notifications
You must be signed in to change notification settings - Fork 20
/
type.go
77 lines (63 loc) · 1.54 KB
/
type.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
package tosca_v2_0
import (
"sync"
"github.com/tliron/puccini/tosca"
)
//
// Type
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.7.1
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.7.1
// [TOSCA-Simple-Profile-YAML-v1.1] @ 3.6.1
//
type Type struct {
*Entity `json:"-" yaml:"-"`
Name string `namespace:""`
ParentName *string `read:"derived_from"`
Version *Version `read:"version,version"`
Metadata Metadata `read:"metadata,!Metadata"`
Description *string `read:"description"`
metadataLock sync.RWMutex
}
func NewType(context *tosca.Context) *Type {
return &Type{
Entity: NewEntity(context),
Name: context.Name,
}
}
// tosca.HasMetadata interface
func (self *Type) GetDescription() (string, bool) {
self.metadataLock.RLock()
defer self.metadataLock.RUnlock()
if self.Description != nil {
return *self.Description, true
}
return "", false
}
// tosca.HasMetadata interface
func (self *Type) GetMetadata() (map[string]string, bool) {
self.metadataLock.RLock()
defer self.metadataLock.RUnlock()
metadata := make(map[string]string)
if self.Metadata != nil {
for key, value := range self.Metadata {
metadata[key] = value
}
}
return metadata, true
}
// tosca.HasMetadata interface
func (self *Type) SetMetadata(name string, value string) bool {
self.metadataLock.Lock()
defer self.metadataLock.Unlock()
self.Metadata[name] = value
return true
}
func (self *Type) GetMetadataValue(key string) (string, bool) {
if self.Metadata != nil {
value, ok := self.Metadata[key]
return value, ok
}
return "", false
}