github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/description/annotations.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package description 5 6 import ( 7 "github.com/juju/schema" 8 ) 9 10 // Instead of copy / pasting the Annotations, SetAnnotations, and the import 11 // three lines into every entity that has annotations, the Annotations_ helper 12 // type is provided for use in composition. This type is composed without a 13 // name so the methods get promoted so they satisfy the HasAnnotations 14 // interface. 15 // 16 // NOTE(mjs) - The type is exported due to a limitation with go-yaml under 17 // 1.6. Once that's fixed it should be possible to make it private again. 18 // 19 // NOTE(mjs) - The trailing underscore on the type name is to avoid collisions 20 // between the type name and the Annotations method. The underscore can go once 21 // the type becomes private again (revert to "annotations"). 22 type Annotations_ map[string]string 23 24 // Annotations implements HasAnnotations. 25 func (a *Annotations_) Annotations() map[string]string { 26 if a == nil { 27 return nil 28 } 29 return *a 30 } 31 32 // SetAnnotations implements HasAnnotations. 33 func (a *Annotations_) SetAnnotations(annotations map[string]string) { 34 *a = annotations 35 } 36 37 func (a *Annotations_) importAnnotations(valid map[string]interface{}) { 38 if annotations := convertToStringMap(valid["annotations"]); annotations != nil { 39 a.SetAnnotations(annotations) 40 } 41 } 42 43 func addAnnotationSchema(fields schema.Fields, defaults schema.Defaults) { 44 fields["annotations"] = schema.StringMap(schema.String()) 45 defaults["annotations"] = schema.Omit 46 }