-
Notifications
You must be signed in to change notification settings - Fork 23
/
annotations.go
53 lines (45 loc) · 1.7 KB
/
annotations.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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package description
import (
"github.com/juju/schema"
)
// HasAnnotations defines the common methods for setting and
// getting annotations for the various entities.
type HasAnnotations interface {
Annotations() map[string]string
SetAnnotations(map[string]string)
}
// Instead of copy / pasting the Annotations, SetAnnotations, and the import
// three lines into every entity that has annotations, the Annotations_ helper
// type is provided for use in composition. This type is composed without a
// name so the methods get promoted so they satisfy the HasAnnotations
// interface.
//
// NOTE(mjs) - The type is exported due to a limitation with go-yaml under
// 1.6. Once that's fixed it should be possible to make it private again.
//
// NOTE(mjs) - The trailing underscore on the type name is to avoid collisions
// between the type name and the Annotations method. The underscore can go once
// the type becomes private again (revert to "annotations").
type Annotations_ map[string]string
// Annotations implements HasAnnotations.
func (a *Annotations_) Annotations() map[string]string {
if a == nil {
return nil
}
return *a
}
// SetAnnotations implements HasAnnotations.
func (a *Annotations_) SetAnnotations(annotations map[string]string) {
*a = annotations
}
func (a *Annotations_) importAnnotations(valid map[string]interface{}) {
if annotations := convertToStringMap(valid["annotations"]); annotations != nil {
a.SetAnnotations(annotations)
}
}
func addAnnotationSchema(fields schema.Fields, defaults schema.Defaults) {
fields["annotations"] = schema.StringMap(schema.String())
defaults["annotations"] = schema.Omit
}