github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/stacktemplates/results.go (about)

     1  package stacktemplates
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  )
     8  
     9  // GetResult represents the result of a Get operation.
    10  type GetResult struct {
    11  	gophercloud.Result
    12  }
    13  
    14  // Extract returns the JSON template and is called after a Get operation.
    15  func (r GetResult) Extract() ([]byte, error) {
    16  	if r.Err != nil {
    17  		return nil, r.Err
    18  	}
    19  	template, err := json.MarshalIndent(r.Body, "", "  ")
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  	return template, nil
    24  }
    25  
    26  // ValidatedTemplate represents the parsed object returned from a Validate request.
    27  type ValidatedTemplate struct {
    28  	Description     string                 `json:"Description"`
    29  	Parameters      map[string]interface{} `json:"Parameters"`
    30  	ParameterGroups map[string]interface{} `json:"ParameterGroups"`
    31  }
    32  
    33  // ValidateResult represents the result of a Validate operation.
    34  type ValidateResult struct {
    35  	gophercloud.Result
    36  }
    37  
    38  // Extract returns a pointer to a ValidatedTemplate object and is called after a
    39  // Validate operation.
    40  func (r ValidateResult) Extract() (*ValidatedTemplate, error) {
    41  	var s *ValidatedTemplate
    42  	err := r.ExtractInto(&s)
    43  	return s, err
    44  }