-
Notifications
You must be signed in to change notification settings - Fork 5
/
delete_service_instance_destination.go
47 lines (42 loc) · 1.21 KB
/
delete_service_instance_destination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package clients
import (
"bytes"
"cf-html5-apps-repo-cli-plugin/log"
"fmt"
"io"
"net/http"
)
// DeleteServiceInstanceDestination delete destination service instance level destination
func DeleteServiceInstanceDestination(serviceURL string, accessToken string, destinationName string) error {
var err error
var request *http.Request
var response *http.Response
var destinationsURL string
var payload = []byte{}
var body []byte
destinationsURL = serviceURL + "/destination-configuration/v1/instanceDestinations/" + destinationName
log.Tracef("Making request to: %s\n", destinationsURL)
request, err = http.NewRequest("DELETE", destinationsURL, bytes.NewBuffer(payload))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", "Bearer "+accessToken)
client, err := GetDefaultClient()
if err != nil {
return err
}
response, err = client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
log.Trace(log.Response{Head: response})
if response.StatusCode > 201 {
body, err = io.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("Could not delete destination: [%s] %+v", response.Status, body)
}
}
return nil
}