3
3
package logpush
4
4
5
5
import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "net/http"
10
+
11
+ "github.com/cloudflare/cloudflare-go/v5/internal/apijson"
12
+ "github.com/cloudflare/cloudflare-go/v5/internal/param"
13
+ "github.com/cloudflare/cloudflare-go/v5/internal/requestconfig"
6
14
"github.com/cloudflare/cloudflare-go/v5/option"
15
+ "github.com/cloudflare/cloudflare-go/v5/packages/pagination"
7
16
)
8
17
9
18
// EdgeService contains methods and other services that help with interacting with
@@ -24,3 +33,242 @@ func NewEdgeService(opts ...option.RequestOption) (r *EdgeService) {
24
33
r .Options = opts
25
34
return
26
35
}
36
+
37
+ // Creates a new Instant Logs job for a zone.
38
+ func (r * EdgeService ) New (ctx context.Context , params EdgeNewParams , opts ... option.RequestOption ) (res * InstantLogpushJob , err error ) {
39
+ var env EdgeNewResponseEnvelope
40
+ opts = append (r .Options [:], opts ... )
41
+ if params .ZoneID .Value == "" {
42
+ err = errors .New ("missing required zone_id parameter" )
43
+ return
44
+ }
45
+ path := fmt .Sprintf ("zones/%s/logpush/edge/jobs" , params .ZoneID )
46
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , params , & env , opts ... )
47
+ if err != nil {
48
+ return
49
+ }
50
+ res = & env .Result
51
+ return
52
+ }
53
+
54
+ // Lists Instant Logs jobs for a zone.
55
+ func (r * EdgeService ) Get (ctx context.Context , query EdgeGetParams , opts ... option.RequestOption ) (res * pagination.SinglePage [InstantLogpushJob ], err error ) {
56
+ var raw * http.Response
57
+ opts = append (r .Options [:], opts ... )
58
+ opts = append ([]option.RequestOption {option .WithResponseInto (& raw )}, opts ... )
59
+ if query .ZoneID .Value == "" {
60
+ err = errors .New ("missing required zone_id parameter" )
61
+ return
62
+ }
63
+ path := fmt .Sprintf ("zones/%s/logpush/edge/jobs" , query .ZoneID )
64
+ cfg , err := requestconfig .NewRequestConfig (ctx , http .MethodGet , path , nil , & res , opts ... )
65
+ if err != nil {
66
+ return nil , err
67
+ }
68
+ err = cfg .Execute ()
69
+ if err != nil {
70
+ return nil , err
71
+ }
72
+ res .SetPageConfig (cfg , raw )
73
+ return res , nil
74
+ }
75
+
76
+ // Lists Instant Logs jobs for a zone.
77
+ func (r * EdgeService ) GetAutoPaging (ctx context.Context , query EdgeGetParams , opts ... option.RequestOption ) * pagination.SinglePageAutoPager [InstantLogpushJob ] {
78
+ return pagination .NewSinglePageAutoPager (r .Get (ctx , query , opts ... ))
79
+ }
80
+
81
+ type InstantLogpushJob struct {
82
+ // Unique WebSocket address that will receive messages from Cloudflare’s edge.
83
+ DestinationConf string `json:"destination_conf" format:"uri"`
84
+ // Comma-separated list of fields.
85
+ Fields string `json:"fields"`
86
+ // Filters to drill down into specific events.
87
+ Filter string `json:"filter"`
88
+ // The sample parameter is the sample rate of the records set by the client:
89
+ // "sample": 1 is 100% of records "sample": 10 is 10% and so on.
90
+ Sample int64 `json:"sample"`
91
+ // Unique session id of the job.
92
+ SessionID string `json:"session_id"`
93
+ JSON instantLogpushJobJSON `json:"-"`
94
+ }
95
+
96
+ // instantLogpushJobJSON contains the JSON metadata for the struct
97
+ // [InstantLogpushJob]
98
+ type instantLogpushJobJSON struct {
99
+ DestinationConf apijson.Field
100
+ Fields apijson.Field
101
+ Filter apijson.Field
102
+ Sample apijson.Field
103
+ SessionID apijson.Field
104
+ raw string
105
+ ExtraFields map [string ]apijson.Field
106
+ }
107
+
108
+ func (r * InstantLogpushJob ) UnmarshalJSON (data []byte ) (err error ) {
109
+ return apijson .UnmarshalRoot (data , r )
110
+ }
111
+
112
+ func (r instantLogpushJobJSON ) RawJSON () string {
113
+ return r .raw
114
+ }
115
+
116
+ type EdgeNewParams struct {
117
+ // Identifier.
118
+ ZoneID param.Field [string ] `path:"zone_id,required"`
119
+ // Comma-separated list of fields.
120
+ Fields param.Field [string ] `json:"fields"`
121
+ // Filters to drill down into specific events.
122
+ Filter param.Field [string ] `json:"filter"`
123
+ // The sample parameter is the sample rate of the records set by the client:
124
+ // "sample": 1 is 100% of records "sample": 10 is 10% and so on.
125
+ Sample param.Field [int64 ] `json:"sample"`
126
+ }
127
+
128
+ func (r EdgeNewParams ) MarshalJSON () (data []byte , err error ) {
129
+ return apijson .MarshalRoot (r )
130
+ }
131
+
132
+ type EdgeNewResponseEnvelope struct {
133
+ Errors []EdgeNewResponseEnvelopeErrors `json:"errors,required"`
134
+ Messages []EdgeNewResponseEnvelopeMessages `json:"messages,required"`
135
+ // Whether the API call was successful.
136
+ Success EdgeNewResponseEnvelopeSuccess `json:"success,required"`
137
+ Result InstantLogpushJob `json:"result,nullable"`
138
+ JSON edgeNewResponseEnvelopeJSON `json:"-"`
139
+ }
140
+
141
+ // edgeNewResponseEnvelopeJSON contains the JSON metadata for the struct
142
+ // [EdgeNewResponseEnvelope]
143
+ type edgeNewResponseEnvelopeJSON struct {
144
+ Errors apijson.Field
145
+ Messages apijson.Field
146
+ Success apijson.Field
147
+ Result apijson.Field
148
+ raw string
149
+ ExtraFields map [string ]apijson.Field
150
+ }
151
+
152
+ func (r * EdgeNewResponseEnvelope ) UnmarshalJSON (data []byte ) (err error ) {
153
+ return apijson .UnmarshalRoot (data , r )
154
+ }
155
+
156
+ func (r edgeNewResponseEnvelopeJSON ) RawJSON () string {
157
+ return r .raw
158
+ }
159
+
160
+ type EdgeNewResponseEnvelopeErrors struct {
161
+ Code int64 `json:"code,required"`
162
+ Message string `json:"message,required"`
163
+ DocumentationURL string `json:"documentation_url"`
164
+ Source EdgeNewResponseEnvelopeErrorsSource `json:"source"`
165
+ JSON edgeNewResponseEnvelopeErrorsJSON `json:"-"`
166
+ }
167
+
168
+ // edgeNewResponseEnvelopeErrorsJSON contains the JSON metadata for the struct
169
+ // [EdgeNewResponseEnvelopeErrors]
170
+ type edgeNewResponseEnvelopeErrorsJSON struct {
171
+ Code apijson.Field
172
+ Message apijson.Field
173
+ DocumentationURL apijson.Field
174
+ Source apijson.Field
175
+ raw string
176
+ ExtraFields map [string ]apijson.Field
177
+ }
178
+
179
+ func (r * EdgeNewResponseEnvelopeErrors ) UnmarshalJSON (data []byte ) (err error ) {
180
+ return apijson .UnmarshalRoot (data , r )
181
+ }
182
+
183
+ func (r edgeNewResponseEnvelopeErrorsJSON ) RawJSON () string {
184
+ return r .raw
185
+ }
186
+
187
+ type EdgeNewResponseEnvelopeErrorsSource struct {
188
+ Pointer string `json:"pointer"`
189
+ JSON edgeNewResponseEnvelopeErrorsSourceJSON `json:"-"`
190
+ }
191
+
192
+ // edgeNewResponseEnvelopeErrorsSourceJSON contains the JSON metadata for the
193
+ // struct [EdgeNewResponseEnvelopeErrorsSource]
194
+ type edgeNewResponseEnvelopeErrorsSourceJSON struct {
195
+ Pointer apijson.Field
196
+ raw string
197
+ ExtraFields map [string ]apijson.Field
198
+ }
199
+
200
+ func (r * EdgeNewResponseEnvelopeErrorsSource ) UnmarshalJSON (data []byte ) (err error ) {
201
+ return apijson .UnmarshalRoot (data , r )
202
+ }
203
+
204
+ func (r edgeNewResponseEnvelopeErrorsSourceJSON ) RawJSON () string {
205
+ return r .raw
206
+ }
207
+
208
+ type EdgeNewResponseEnvelopeMessages struct {
209
+ Code int64 `json:"code,required"`
210
+ Message string `json:"message,required"`
211
+ DocumentationURL string `json:"documentation_url"`
212
+ Source EdgeNewResponseEnvelopeMessagesSource `json:"source"`
213
+ JSON edgeNewResponseEnvelopeMessagesJSON `json:"-"`
214
+ }
215
+
216
+ // edgeNewResponseEnvelopeMessagesJSON contains the JSON metadata for the struct
217
+ // [EdgeNewResponseEnvelopeMessages]
218
+ type edgeNewResponseEnvelopeMessagesJSON struct {
219
+ Code apijson.Field
220
+ Message apijson.Field
221
+ DocumentationURL apijson.Field
222
+ Source apijson.Field
223
+ raw string
224
+ ExtraFields map [string ]apijson.Field
225
+ }
226
+
227
+ func (r * EdgeNewResponseEnvelopeMessages ) UnmarshalJSON (data []byte ) (err error ) {
228
+ return apijson .UnmarshalRoot (data , r )
229
+ }
230
+
231
+ func (r edgeNewResponseEnvelopeMessagesJSON ) RawJSON () string {
232
+ return r .raw
233
+ }
234
+
235
+ type EdgeNewResponseEnvelopeMessagesSource struct {
236
+ Pointer string `json:"pointer"`
237
+ JSON edgeNewResponseEnvelopeMessagesSourceJSON `json:"-"`
238
+ }
239
+
240
+ // edgeNewResponseEnvelopeMessagesSourceJSON contains the JSON metadata for the
241
+ // struct [EdgeNewResponseEnvelopeMessagesSource]
242
+ type edgeNewResponseEnvelopeMessagesSourceJSON struct {
243
+ Pointer apijson.Field
244
+ raw string
245
+ ExtraFields map [string ]apijson.Field
246
+ }
247
+
248
+ func (r * EdgeNewResponseEnvelopeMessagesSource ) UnmarshalJSON (data []byte ) (err error ) {
249
+ return apijson .UnmarshalRoot (data , r )
250
+ }
251
+
252
+ func (r edgeNewResponseEnvelopeMessagesSourceJSON ) RawJSON () string {
253
+ return r .raw
254
+ }
255
+
256
+ // Whether the API call was successful.
257
+ type EdgeNewResponseEnvelopeSuccess bool
258
+
259
+ const (
260
+ EdgeNewResponseEnvelopeSuccessTrue EdgeNewResponseEnvelopeSuccess = true
261
+ )
262
+
263
+ func (r EdgeNewResponseEnvelopeSuccess ) IsKnown () bool {
264
+ switch r {
265
+ case EdgeNewResponseEnvelopeSuccessTrue :
266
+ return true
267
+ }
268
+ return false
269
+ }
270
+
271
+ type EdgeGetParams struct {
272
+ // Identifier.
273
+ ZoneID param.Field [string ] `path:"zone_id,required"`
274
+ }
0 commit comments