-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_synthetic_checks.go
More file actions
110 lines (103 loc) · 3.75 KB
/
client_synthetic_checks.go
File metadata and controls
110 lines (103 loc) · 3.75 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package dash0
import (
"context"
"fmt"
"net/http"
)
// ListSyntheticChecks retrieves all synthetic checks.
func (c *client) ListSyntheticChecks(ctx context.Context, dataset *string) ([]*SyntheticChecksApiListItem, error) {
if err := c.requireAPI(); err != nil {
return nil, err
}
params := &GetApiSyntheticChecksParams{
Dataset: dataset,
}
resp, err := c.inner.GetApiSyntheticChecksWithResponse(ctx, params)
if err != nil {
return nil, fmt.Errorf("dash0: list synthetic checks failed: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return nil, newAPIErrorWithBody(resp.HTTPResponse, resp.Body)
}
if resp.JSON200 == nil {
return nil, fmt.Errorf("dash0: unexpected nil response")
}
return toPointerSlice(*resp.JSON200), nil
}
// GetSyntheticCheck retrieves a synthetic check by origin or ID.
func (c *client) GetSyntheticCheck(ctx context.Context, originOrID string, dataset *string) (*SyntheticCheckDefinition, error) {
if err := c.requireAPI(); err != nil {
return nil, err
}
params := &GetApiSyntheticChecksOriginOrIdParams{
Dataset: dataset,
}
resp, err := c.inner.GetApiSyntheticChecksOriginOrIdWithResponse(ctx, originOrID, params)
if err != nil {
return nil, fmt.Errorf("dash0: get synthetic check failed: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return nil, newAPIErrorWithBody(resp.HTTPResponse, resp.Body)
}
return resp.JSON200, nil
}
// CreateSyntheticCheck creates a new synthetic check.
func (c *client) CreateSyntheticCheck(ctx context.Context, check *SyntheticCheckDefinition, dataset *string) (*SyntheticCheckDefinition, error) {
if err := c.requireAPI(); err != nil {
return nil, err
}
params := &PostApiSyntheticChecksParams{
Dataset: dataset,
}
resp, err := c.inner.PostApiSyntheticChecksWithResponse(ctx, params, *check)
if err != nil {
return nil, fmt.Errorf("dash0: create synthetic check failed: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return nil, newAPIErrorWithBody(resp.HTTPResponse, resp.Body)
}
return resp.JSON200, nil
}
// UpdateSyntheticCheck updates an existing synthetic check.
func (c *client) UpdateSyntheticCheck(ctx context.Context, originOrID string, check *SyntheticCheckDefinition, dataset *string) (*SyntheticCheckDefinition, error) {
if err := c.requireAPI(); err != nil {
return nil, err
}
params := &PutApiSyntheticChecksOriginOrIdParams{
Dataset: dataset,
}
resp, err := c.inner.PutApiSyntheticChecksOriginOrIdWithResponse(ctx, originOrID, params, *check)
if err != nil {
return nil, fmt.Errorf("dash0: update synthetic check failed: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return nil, newAPIErrorWithBody(resp.HTTPResponse, resp.Body)
}
return resp.JSON200, nil
}
// DeleteSyntheticCheck deletes a synthetic check by origin or ID.
func (c *client) DeleteSyntheticCheck(ctx context.Context, originOrID string, dataset *string) error {
if err := c.requireAPI(); err != nil {
return err
}
params := &DeleteApiSyntheticChecksOriginOrIdParams{
Dataset: dataset,
}
resp, err := c.inner.DeleteApiSyntheticChecksOriginOrIdWithResponse(ctx, originOrID, params)
if err != nil {
return fmt.Errorf("dash0: delete synthetic check failed: %w", err)
}
if resp.StatusCode() != http.StatusOK && resp.StatusCode() != http.StatusNoContent {
return newAPIErrorWithBody(resp.HTTPResponse, resp.Body)
}
return nil
}
// ListSyntheticChecksIter returns an iterator over all synthetic checks.
// This is a convenience wrapper around ListSyntheticChecks for consistent iteration patterns.
func (c *client) ListSyntheticChecksIter(ctx context.Context, dataset *string) *Iter[SyntheticChecksApiListItem] {
items, err := c.ListSyntheticChecks(ctx, dataset)
if err != nil {
return newIterWithError[SyntheticChecksApiListItem](err)
}
return newIter(items, false, nil, nil)
}