github.com/gophercloud/gophercloud@v1.11.0/openstack/container/v1/capsules/template.go (about)

     1  package capsules
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	yaml "gopkg.in/yaml.v2"
     7  )
     8  
     9  // Template is a structure that represents OpenStack Zun Capsule templates
    10  type Template struct {
    11  	// Bin stores the contents of the template or environment.
    12  	Bin []byte
    13  	// Parsed contains a parsed version of Bin. Since there are 2 different
    14  	// fields referring to the same value, you must be careful when accessing
    15  	// this filed.
    16  	Parsed map[string]interface{}
    17  }
    18  
    19  // Parse will parse the contents and then validate. The contents MUST be either JSON or YAML.
    20  func (t *Template) Parse() error {
    21  	if jerr := json.Unmarshal(t.Bin, &t.Parsed); jerr != nil {
    22  		if yerr := yaml.Unmarshal(t.Bin, &t.Parsed); yerr != nil {
    23  			return ErrInvalidDataFormat{}
    24  		}
    25  	}
    26  	return nil
    27  }