github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/gaussdb/v3/instance/DeleteInstance.go (about)

     1  package instance
     2  
     3  import (
     4  	"net/http"
     5  
     6  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     8  )
     9  
    10  // DeleteInstance
    11  // return ID of DB instance deletion task
    12  func DeleteInstance(client *golangsdk.ServiceClient, instanceId string) (*string, error) {
    13  	// DELETE https://{Endpoint}/mysql/v3/{project_id}/instances/{instance_id}
    14  	raw, err := client.Delete(client.ServiceURL("instances", instanceId), &golangsdk.RequestOpts{
    15  		OkCodes:     []int{200, 202},
    16  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
    17  	})
    18  	return extraJob(err, raw)
    19  }
    20  
    21  func extraJob(err error, raw *http.Response) (*string, error) {
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	var res struct {
    27  		JobId string `json:"job_id"`
    28  	}
    29  	err = extract.Into(raw.Body, &res)
    30  	return &res.JobId, err
    31  }