-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.go
31 lines (27 loc) · 922 Bytes
/
delete.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
package main
import (
"context"
"fmt"
"form3-accountapi-client/uuid"
"net/http"
)
func (a *accountClient) Delete(ctx context.Context, accountId uuid.UUID, version int64) error {
accountPath := fmt.Sprintf("%s%s/%s?version=%d", a.baseUrl.String(), endpointAccounts, accountId.String(), version)
requestMethod := http.MethodDelete
req, err := http.NewRequest(requestMethod, accountPath, nil)
if err != nil {
return &ErrInvalidRequest{requestMethod, endpointAccounts, err.Error()}
}
resp, err := a.httpClient.Do(req)
if err != nil {
return newGenericAccountError(requestMethod, accountPath, err.Error(), resp.StatusCode)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
return &ErrAccountNotFound{accountId, version}
}
if resp.StatusCode != http.StatusNoContent {
return newGenericAccountError(requestMethod, accountPath, "invalid response code from api", 0)
}
return nil
}