github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/rts/v1/stacktemplates/results.go (about)

     1  package stacktemplates
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud"
     7  )
     8  
     9  // GetResult represents the result of a Get operation.
    10  type GetResult struct {
    11  	golangsdk.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  	mapBody := make(map[string]interface{})
    20  
    21  	// make sure return pretty-printed body
    22  	if err := json.Unmarshal(r.Body, &mapBody); err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	template, err := json.MarshalIndent(mapBody, "", "  ")
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	return template, nil
    31  }