Delete sends a “DELETE” request to the Pushgateway configured while creating this Pusher, using the configured job name and any added grouping labels as grouping key. Any added Gatherers and Collectors added to this Pusher are ignored by this method. Delete returns the first error encountered by an
()
| 238 | // Delete returns the first error encountered by any method call (including this |
| 239 | // one) in the lifetime of the Pusher. |
| 240 | func (p *Pusher) Delete() error { |
| 241 | if p.error != nil { |
| 242 | return p.error |
| 243 | } |
| 244 | req, err := http.NewRequest(http.MethodDelete, p.fullURL(), nil) |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | if p.header != nil { |
| 249 | req.Header = p.header |
| 250 | } |
| 251 | if p.useBasicAuth { |
| 252 | req.SetBasicAuth(p.username, p.password) |
| 253 | } |
| 254 | resp, err := p.client.Do(req) |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | defer resp.Body.Close() |
| 259 | if resp.StatusCode != http.StatusAccepted { |
| 260 | body, _ := io.ReadAll(resp.Body) // Ignore any further error as this is for an error message only. |
| 261 | return fmt.Errorf("unexpected status code %d while deleting %s: %s", resp.StatusCode, p.fullURL(), body) |
| 262 | } |
| 263 | return nil |
| 264 | } |
| 265 | |
| 266 | func (p *Pusher) push(ctx context.Context, method string) error { |
| 267 | if p.error != nil { |