/
monitorpreview.go
193 lines (171 loc) · 7.96 KB
/
monitorpreview.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package load_balancers
import (
"context"
"fmt"
"net/http"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
)
// MonitorPreviewService contains methods and other services that help with
// interacting with the cloudflare API. Note, unlike clients, this service does not
// read variables from the environment automatically. You should not instantiate
// this service directly, and instead use the [NewMonitorPreviewService] method
// instead.
type MonitorPreviewService struct {
Options []option.RequestOption
}
// NewMonitorPreviewService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewMonitorPreviewService(opts ...option.RequestOption) (r *MonitorPreviewService) {
r = &MonitorPreviewService{}
r.Options = opts
return
}
// Preview pools using the specified monitor with provided monitor details. The
// returned preview_id can be used in the preview endpoint to retrieve the results.
func (r *MonitorPreviewService) New(ctx context.Context, monitorID string, params MonitorPreviewNewParams, opts ...option.RequestOption) (res *MonitorPreviewNewResponse, err error) {
opts = append(r.Options[:], opts...)
var env MonitorPreviewNewResponseEnvelope
path := fmt.Sprintf("accounts/%s/load_balancers/monitors/%s/preview", params.AccountID, monitorID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type MonitorPreviewNewResponse struct {
// Monitored pool IDs mapped to their respective names.
Pools map[string]string `json:"pools"`
PreviewID string `json:"preview_id"`
JSON monitorPreviewNewResponseJSON `json:"-"`
}
// monitorPreviewNewResponseJSON contains the JSON metadata for the struct
// [MonitorPreviewNewResponse]
type monitorPreviewNewResponseJSON struct {
Pools apijson.Field
PreviewID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MonitorPreviewNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r monitorPreviewNewResponseJSON) RawJSON() string {
return r.raw
}
type MonitorPreviewNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// The expected HTTP response code or code range of the health check. This
// parameter is only valid for HTTP and HTTPS monitors.
ExpectedCodes param.Field[string] `json:"expected_codes,required"`
// Do not validate the certificate when monitor use HTTPS. This parameter is
// currently only valid for HTTP and HTTPS monitors.
AllowInsecure param.Field[bool] `json:"allow_insecure"`
// To be marked unhealthy the monitored origin must fail this healthcheck N
// consecutive times.
ConsecutiveDown param.Field[int64] `json:"consecutive_down"`
// To be marked healthy the monitored origin must pass this healthcheck N
// consecutive times.
ConsecutiveUp param.Field[int64] `json:"consecutive_up"`
// Object description.
Description param.Field[string] `json:"description"`
// A case-insensitive sub-string to look for in the response body. If this string
// is not found, the origin will be marked as unhealthy. This parameter is only
// valid for HTTP and HTTPS monitors.
ExpectedBody param.Field[string] `json:"expected_body"`
// Follow redirects if returned by the origin. This parameter is only valid for
// HTTP and HTTPS monitors.
FollowRedirects param.Field[bool] `json:"follow_redirects"`
// The HTTP request headers to send in the health check. It is recommended you set
// a Host header by default. The User-Agent header cannot be overridden. This
// parameter is only valid for HTTP and HTTPS monitors.
Header param.Field[interface{}] `json:"header"`
// The interval between each health check. Shorter intervals may improve failover
// time, but will increase load on the origins as we check from multiple locations.
Interval param.Field[int64] `json:"interval"`
// The method to use for the health check. This defaults to 'GET' for HTTP/HTTPS
// based checks and 'connection_established' for TCP based health checks.
Method param.Field[string] `json:"method"`
// The endpoint path you want to conduct a health check against. This parameter is
// only valid for HTTP and HTTPS monitors.
Path param.Field[string] `json:"path"`
// The port number to connect to for the health check. Required for TCP, UDP, and
// SMTP checks. HTTP and HTTPS checks should only define the port when using a
// non-standard port (HTTP: default 80, HTTPS: default 443).
Port param.Field[int64] `json:"port"`
// Assign this monitor to emulate the specified zone while probing. This parameter
// is only valid for HTTP and HTTPS monitors.
ProbeZone param.Field[string] `json:"probe_zone"`
// The number of retries to attempt in case of a timeout before marking the origin
// as unhealthy. Retries are attempted immediately.
Retries param.Field[int64] `json:"retries"`
// The timeout (in seconds) before marking the health check as failed.
Timeout param.Field[int64] `json:"timeout"`
// The protocol to use for the health check. Currently supported protocols are
// 'HTTP','HTTPS', 'TCP', 'ICMP-PING', 'UDP-ICMP', and 'SMTP'.
Type param.Field[MonitorPreviewNewParamsType] `json:"type"`
}
func (r MonitorPreviewNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The protocol to use for the health check. Currently supported protocols are
// 'HTTP','HTTPS', 'TCP', 'ICMP-PING', 'UDP-ICMP', and 'SMTP'.
type MonitorPreviewNewParamsType string
const (
MonitorPreviewNewParamsTypeHTTP MonitorPreviewNewParamsType = "http"
MonitorPreviewNewParamsTypeHTTPS MonitorPreviewNewParamsType = "https"
MonitorPreviewNewParamsTypeTCP MonitorPreviewNewParamsType = "tcp"
MonitorPreviewNewParamsTypeUdpIcmp MonitorPreviewNewParamsType = "udp_icmp"
MonitorPreviewNewParamsTypeIcmpPing MonitorPreviewNewParamsType = "icmp_ping"
MonitorPreviewNewParamsTypeSmtp MonitorPreviewNewParamsType = "smtp"
)
func (r MonitorPreviewNewParamsType) IsKnown() bool {
switch r {
case MonitorPreviewNewParamsTypeHTTP, MonitorPreviewNewParamsTypeHTTPS, MonitorPreviewNewParamsTypeTCP, MonitorPreviewNewParamsTypeUdpIcmp, MonitorPreviewNewParamsTypeIcmpPing, MonitorPreviewNewParamsTypeSmtp:
return true
}
return false
}
type MonitorPreviewNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result MonitorPreviewNewResponse `json:"result,required"`
// Whether the API call was successful
Success MonitorPreviewNewResponseEnvelopeSuccess `json:"success,required"`
JSON monitorPreviewNewResponseEnvelopeJSON `json:"-"`
}
// monitorPreviewNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [MonitorPreviewNewResponseEnvelope]
type monitorPreviewNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MonitorPreviewNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r monitorPreviewNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type MonitorPreviewNewResponseEnvelopeSuccess bool
const (
MonitorPreviewNewResponseEnvelopeSuccessTrue MonitorPreviewNewResponseEnvelopeSuccess = true
)
func (r MonitorPreviewNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case MonitorPreviewNewResponseEnvelopeSuccessTrue:
return true
}
return false
}