-
Notifications
You must be signed in to change notification settings - Fork 11
/
rm.go
44 lines (41 loc) · 1.1 KB
/
rm.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
package main
import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
)
type RmCommand struct {
MarkerID string `short:"i" long:"id" description:"ID of the marker to delete" required:"true"`
}
func (r *RmCommand) Execute(args []string) error {
checkRequiredFlags()
postURL, err := url.Parse(options.APIHost)
if err != nil {
errMsg := fmt.Sprintf("Failed to parse URL %s", options.APIHost)
return errors.New(errMsg)
}
postURL.Path = "/1/markers/" + options.Dataset + "/" + r.MarkerID
req, _ := http.NewRequest("DELETE", postURL.String(), nil)
req.Header.Set("User-Agent", UserAgent)
req.Header.Add("X-Honeycomb-Team", options.WriteKey)
if options.AuthorizationHeader != "" {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", options.AuthorizationHeader))
}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("Failed with %d and message: %s", resp.StatusCode, body)
return errors.New(errMsg)
}
fmt.Println(string(body))
return nil
}