/
loadbalancer.go
2541 lines (2337 loc) · 123 KB
/
loadbalancer.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package load_balancers
import (
"context"
"fmt"
"net/http"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"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"
)
// LoadBalancerService 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 [NewLoadBalancerService] method
// instead.
type LoadBalancerService struct {
Options []option.RequestOption
Monitors *MonitorService
Pools *PoolService
Previews *PreviewService
Regions *RegionService
Searches *SearchService
}
// NewLoadBalancerService 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 NewLoadBalancerService(opts ...option.RequestOption) (r *LoadBalancerService) {
r = &LoadBalancerService{}
r.Options = opts
r.Monitors = NewMonitorService(opts...)
r.Pools = NewPoolService(opts...)
r.Previews = NewPreviewService(opts...)
r.Regions = NewRegionService(opts...)
r.Searches = NewSearchService(opts...)
return
}
// Create a new load balancer.
func (r *LoadBalancerService) New(ctx context.Context, params LoadBalancerNewParams, opts ...option.RequestOption) (res *LoadBalancer, err error) {
opts = append(r.Options[:], opts...)
var env LoadBalancerNewResponseEnvelope
path := fmt.Sprintf("zones/%s/load_balancers", params.ZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Update a configured load balancer.
func (r *LoadBalancerService) Update(ctx context.Context, loadBalancerID string, params LoadBalancerUpdateParams, opts ...option.RequestOption) (res *LoadBalancer, err error) {
opts = append(r.Options[:], opts...)
var env LoadBalancerUpdateResponseEnvelope
path := fmt.Sprintf("zones/%s/load_balancers/%s", params.ZoneID, loadBalancerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// List configured load balancers.
func (r *LoadBalancerService) List(ctx context.Context, query LoadBalancerListParams, opts ...option.RequestOption) (res *pagination.SinglePage[LoadBalancer], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("zones/%s/load_balancers", query.ZoneID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List configured load balancers.
func (r *LoadBalancerService) ListAutoPaging(ctx context.Context, query LoadBalancerListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[LoadBalancer] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}
// Delete a configured load balancer.
func (r *LoadBalancerService) Delete(ctx context.Context, loadBalancerID string, params LoadBalancerDeleteParams, opts ...option.RequestOption) (res *LoadBalancerDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
var env LoadBalancerDeleteResponseEnvelope
path := fmt.Sprintf("zones/%s/load_balancers/%s", params.ZoneID, loadBalancerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Apply changes to an existing load balancer, overwriting the supplied properties.
func (r *LoadBalancerService) Edit(ctx context.Context, loadBalancerID string, params LoadBalancerEditParams, opts ...option.RequestOption) (res *LoadBalancer, err error) {
opts = append(r.Options[:], opts...)
var env LoadBalancerEditResponseEnvelope
path := fmt.Sprintf("zones/%s/load_balancers/%s", params.ZoneID, loadBalancerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Fetch a single configured load balancer.
func (r *LoadBalancerService) Get(ctx context.Context, loadBalancerID string, query LoadBalancerGetParams, opts ...option.RequestOption) (res *LoadBalancer, err error) {
opts = append(r.Options[:], opts...)
var env LoadBalancerGetResponseEnvelope
path := fmt.Sprintf("zones/%s/load_balancers/%s", query.ZoneID, loadBalancerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Controls features that modify the routing of requests to pools and origins in
// response to dynamic conditions, such as during the interval between active
// health monitoring requests. For example, zero-downtime failover occurs
// immediately when an origin becomes unavailable due to HTTP 521, 522, or 523
// response codes. If there is another healthy origin in the same pool, the request
// is retried once against this alternate origin.
type AdaptiveRouting struct {
// Extends zero-downtime failover of requests to healthy origins from alternate
// pools, when no healthy alternate exists in the same pool, according to the
// failover order defined by traffic and origin steering. When set false (the
// default) zero-downtime failover will only occur between origins within the same
// pool. See `session_affinity_attributes` for control over when sessions are
// broken or reassigned.
FailoverAcrossPools bool `json:"failover_across_pools"`
JSON adaptiveRoutingJSON `json:"-"`
}
// adaptiveRoutingJSON contains the JSON metadata for the struct [AdaptiveRouting]
type adaptiveRoutingJSON struct {
FailoverAcrossPools apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AdaptiveRouting) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r adaptiveRoutingJSON) RawJSON() string {
return r.raw
}
// Controls features that modify the routing of requests to pools and origins in
// response to dynamic conditions, such as during the interval between active
// health monitoring requests. For example, zero-downtime failover occurs
// immediately when an origin becomes unavailable due to HTTP 521, 522, or 523
// response codes. If there is another healthy origin in the same pool, the request
// is retried once against this alternate origin.
type AdaptiveRoutingParam struct {
// Extends zero-downtime failover of requests to healthy origins from alternate
// pools, when no healthy alternate exists in the same pool, according to the
// failover order defined by traffic and origin steering. When set false (the
// default) zero-downtime failover will only occur between origins within the same
// pool. See `session_affinity_attributes` for control over when sessions are
// broken or reassigned.
FailoverAcrossPools param.Field[bool] `json:"failover_across_pools"`
}
func (r AdaptiveRoutingParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// WNAM: Western North America, ENAM: Eastern North America, WEU: Western Europe,
// EEU: Eastern Europe, NSAM: Northern South America, SSAM: Southern South America,
// OC: Oceania, ME: Middle East, NAF: North Africa, SAF: South Africa, SAS:
// Southern Asia, SEAS: South East Asia, NEAS: North East Asia, ALL_REGIONS: all
// regions (ENTERPRISE customers only).
type CheckRegion string
const (
CheckRegionWnam CheckRegion = "WNAM"
CheckRegionEnam CheckRegion = "ENAM"
CheckRegionWeu CheckRegion = "WEU"
CheckRegionEeu CheckRegion = "EEU"
CheckRegionNsam CheckRegion = "NSAM"
CheckRegionSsam CheckRegion = "SSAM"
CheckRegionOc CheckRegion = "OC"
CheckRegionMe CheckRegion = "ME"
CheckRegionNaf CheckRegion = "NAF"
CheckRegionSaf CheckRegion = "SAF"
CheckRegionSas CheckRegion = "SAS"
CheckRegionSeas CheckRegion = "SEAS"
CheckRegionNeas CheckRegion = "NEAS"
CheckRegionAllRegions CheckRegion = "ALL_REGIONS"
)
func (r CheckRegion) IsKnown() bool {
switch r {
case CheckRegionWnam, CheckRegionEnam, CheckRegionWeu, CheckRegionEeu, CheckRegionNsam, CheckRegionSsam, CheckRegionOc, CheckRegionMe, CheckRegionNaf, CheckRegionSaf, CheckRegionSas, CheckRegionSeas, CheckRegionNeas, CheckRegionAllRegions:
return true
}
return false
}
type DefaultPools = string
type DefaultPoolsParam = string
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
type FilterOptions struct {
// If set true, disable notifications for this type of resource (pool or origin).
Disable bool `json:"disable"`
// If present, send notifications only for this health status (e.g. false for only
// DOWN events). Use null to reset (all events).
Healthy bool `json:"healthy,nullable"`
JSON filterOptionsJSON `json:"-"`
}
// filterOptionsJSON contains the JSON metadata for the struct [FilterOptions]
type filterOptionsJSON struct {
Disable apijson.Field
Healthy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FilterOptions) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r filterOptionsJSON) RawJSON() string {
return r.raw
}
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
type FilterOptionsParam struct {
// If set true, disable notifications for this type of resource (pool or origin).
Disable param.Field[bool] `json:"disable"`
// If present, send notifications only for this health status (e.g. false for only
// DOWN events). Use null to reset (all events).
Healthy param.Field[bool] `json:"healthy"`
}
func (r FilterOptionsParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The request header is used to pass additional information with an HTTP request.
// Currently supported header is 'Host'.
type Header struct {
// The 'Host' header allows to override the hostname set in the HTTP request.
// Current support is 1 'Host' header override per origin.
Host []Host `json:"Host"`
JSON headerJSON `json:"-"`
}
// headerJSON contains the JSON metadata for the struct [Header]
type headerJSON struct {
Host apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Header) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r headerJSON) RawJSON() string {
return r.raw
}
// The request header is used to pass additional information with an HTTP request.
// Currently supported header is 'Host'.
type HeaderParam struct {
// The 'Host' header allows to override the hostname set in the HTTP request.
// Current support is 1 'Host' header override per origin.
Host param.Field[[]HostParam] `json:"Host"`
}
func (r HeaderParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type Host = string
type HostParam = string
type LoadBalancer struct {
ID string `json:"id"`
// Controls features that modify the routing of requests to pools and origins in
// response to dynamic conditions, such as during the interval between active
// health monitoring requests. For example, zero-downtime failover occurs
// immediately when an origin becomes unavailable due to HTTP 521, 522, or 523
// response codes. If there is another healthy origin in the same pool, the request
// is retried once against this alternate origin.
AdaptiveRouting AdaptiveRouting `json:"adaptive_routing"`
// A mapping of country codes to a list of pool IDs (ordered by their failover
// priority) for the given country. Any country not explicitly defined will fall
// back to using the corresponding region_pool mapping if it exists else to
// default_pools.
CountryPools interface{} `json:"country_pools"`
CreatedOn time.Time `json:"created_on" format:"date-time"`
// A list of pool IDs ordered by their failover priority. Pools defined here are
// used by default, or when region_pools are not configured for a given region.
DefaultPools []DefaultPools `json:"default_pools"`
// Object description.
Description string `json:"description"`
// Whether to enable (the default) this load balancer.
Enabled bool `json:"enabled"`
// The pool ID to use when all other pools are detected as unhealthy.
FallbackPool interface{} `json:"fallback_pool"`
// Controls location-based steering for non-proxied requests. See `steering_policy`
// to learn how steering is affected.
LocationStrategy LocationStrategy `json:"location_strategy"`
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
// The DNS hostname to associate with your Load Balancer. If this hostname already
// exists as a DNS record in Cloudflare's DNS, the Load Balancer will take
// precedence and the DNS record will not be used.
Name string `json:"name"`
// (Enterprise only): A mapping of Cloudflare PoP identifiers to a list of pool IDs
// (ordered by their failover priority) for the PoP (datacenter). Any PoPs not
// explicitly defined will fall back to using the corresponding country_pool, then
// region_pool mapping if it exists else to default_pools.
PopPools interface{} `json:"pop_pools"`
// Whether the hostname should be gray clouded (false) or orange clouded (true).
Proxied bool `json:"proxied"`
// Configures pool weights.
//
// - `steering_policy="random"`: A random pool is selected with probability
// proportional to pool weights.
// - `steering_policy="least_outstanding_requests"`: Use pool weights to scale each
// pool's outstanding requests.
// - `steering_policy="least_connections"`: Use pool weights to scale each pool's
// open connections.
RandomSteering RandomSteering `json:"random_steering"`
// A mapping of region codes to a list of pool IDs (ordered by their failover
// priority) for the given region. Any regions not explicitly defined will fall
// back to using default_pools.
RegionPools interface{} `json:"region_pools"`
// BETA Field Not General Access: A list of rules for this load balancer to
// execute.
Rules []Rules `json:"rules"`
// Specifies the type of session affinity the load balancer should use unless
// specified as `"none"` or "" (default). The supported types are:
//
// - `"cookie"`: On the first request to a proxied load balancer, a cookie is
// generated, encoding information of which origin the request will be forwarded
// to. Subsequent requests, by the same client to the same load balancer, will be
// sent to the origin server the cookie encodes, for the duration of the cookie
// and as long as the origin server remains healthy. If the cookie has expired or
// the origin server is unhealthy, then a new origin server is calculated and
// used.
// - `"ip_cookie"`: Behaves the same as `"cookie"` except the initial origin
// selection is stable and based on the client's ip address.
// - `"header"`: On the first request to a proxied load balancer, a session key
// based on the configured HTTP headers (see
// `session_affinity_attributes.headers`) is generated, encoding the request
// headers used for storing in the load balancer session state which origin the
// request will be forwarded to. Subsequent requests to the load balancer with
// the same headers will be sent to the same origin server, for the duration of
// the session and as long as the origin server remains healthy. If the session
// has been idle for the duration of `session_affinity_ttl` seconds or the origin
// server is unhealthy, then a new origin server is calculated and used. See
// `headers` in `session_affinity_attributes` for additional required
// configuration.
SessionAffinity LoadBalancerSessionAffinity `json:"session_affinity"`
// Configures attributes for session affinity.
SessionAffinityAttributes SessionAffinityAttributes `json:"session_affinity_attributes"`
// Time, in seconds, until a client's session expires after being created. Once the
// expiry time has been reached, subsequent requests may get sent to a different
// origin server. The accepted ranges per `session_affinity` policy are:
//
// - `"cookie"` / `"ip_cookie"`: The current default of 23 hours will be used
// unless explicitly set. The accepted range of values is between [1800, 604800].
// - `"header"`: The current default of 1800 seconds will be used unless explicitly
// set. The accepted range of values is between [30, 3600]. Note: With session
// affinity by header, sessions only expire after they haven't been used for the
// number of seconds specified.
SessionAffinityTTL float64 `json:"session_affinity_ttl"`
// Steering Policy for this load balancer.
//
// - `"off"`: Use `default_pools`.
// - `"geo"`: Use `region_pools`/`country_pools`/`pop_pools`. For non-proxied
// requests, the country for `country_pools` is determined by
// `location_strategy`.
// - `"random"`: Select a pool randomly.
// - `"dynamic_latency"`: Use round trip time to select the closest pool in
// default_pools (requires pool health checks).
// - `"proximity"`: Use the pools' latitude and longitude to select the closest
// pool using the Cloudflare PoP location for proxied requests or the location
// determined by `location_strategy` for non-proxied requests.
// - `"least_outstanding_requests"`: Select a pool by taking into consideration
// `random_steering` weights, as well as each pool's number of outstanding
// requests. Pools with more pending requests are weighted proportionately less
// relative to others.
// - `"least_connections"`: Select a pool by taking into consideration
// `random_steering` weights, as well as each pool's number of open connections.
// Pools with more open connections are weighted proportionately less relative to
// others. Supported for HTTP/1 and HTTP/2 connections.
// - `""`: Will map to `"geo"` if you use
// `region_pools`/`country_pools`/`pop_pools` otherwise `"off"`.
SteeringPolicy LoadBalancerSteeringPolicy `json:"steering_policy"`
// Time to live (TTL) of the DNS entry for the IP address returned by this load
// balancer. This only applies to gray-clouded (unproxied) load balancers.
TTL float64 `json:"ttl"`
JSON loadBalancerJSON `json:"-"`
}
// loadBalancerJSON contains the JSON metadata for the struct [LoadBalancer]
type loadBalancerJSON struct {
ID apijson.Field
AdaptiveRouting apijson.Field
CountryPools apijson.Field
CreatedOn apijson.Field
DefaultPools apijson.Field
Description apijson.Field
Enabled apijson.Field
FallbackPool apijson.Field
LocationStrategy apijson.Field
ModifiedOn apijson.Field
Name apijson.Field
PopPools apijson.Field
Proxied apijson.Field
RandomSteering apijson.Field
RegionPools apijson.Field
Rules apijson.Field
SessionAffinity apijson.Field
SessionAffinityAttributes apijson.Field
SessionAffinityTTL apijson.Field
SteeringPolicy apijson.Field
TTL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LoadBalancer) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loadBalancerJSON) RawJSON() string {
return r.raw
}
// Specifies the type of session affinity the load balancer should use unless
// specified as `"none"` or "" (default). The supported types are:
//
// - `"cookie"`: On the first request to a proxied load balancer, a cookie is
// generated, encoding information of which origin the request will be forwarded
// to. Subsequent requests, by the same client to the same load balancer, will be
// sent to the origin server the cookie encodes, for the duration of the cookie
// and as long as the origin server remains healthy. If the cookie has expired or
// the origin server is unhealthy, then a new origin server is calculated and
// used.
// - `"ip_cookie"`: Behaves the same as `"cookie"` except the initial origin
// selection is stable and based on the client's ip address.
// - `"header"`: On the first request to a proxied load balancer, a session key
// based on the configured HTTP headers (see
// `session_affinity_attributes.headers`) is generated, encoding the request
// headers used for storing in the load balancer session state which origin the
// request will be forwarded to. Subsequent requests to the load balancer with
// the same headers will be sent to the same origin server, for the duration of
// the session and as long as the origin server remains healthy. If the session
// has been idle for the duration of `session_affinity_ttl` seconds or the origin
// server is unhealthy, then a new origin server is calculated and used. See
// `headers` in `session_affinity_attributes` for additional required
// configuration.
type LoadBalancerSessionAffinity string
const (
LoadBalancerSessionAffinityNone LoadBalancerSessionAffinity = "none"
LoadBalancerSessionAffinityCookie LoadBalancerSessionAffinity = "cookie"
LoadBalancerSessionAffinityIPCookie LoadBalancerSessionAffinity = "ip_cookie"
LoadBalancerSessionAffinityHeader LoadBalancerSessionAffinity = "header"
LoadBalancerSessionAffinityEmpty LoadBalancerSessionAffinity = "\"\""
)
func (r LoadBalancerSessionAffinity) IsKnown() bool {
switch r {
case LoadBalancerSessionAffinityNone, LoadBalancerSessionAffinityCookie, LoadBalancerSessionAffinityIPCookie, LoadBalancerSessionAffinityHeader, LoadBalancerSessionAffinityEmpty:
return true
}
return false
}
// Steering Policy for this load balancer.
//
// - `"off"`: Use `default_pools`.
// - `"geo"`: Use `region_pools`/`country_pools`/`pop_pools`. For non-proxied
// requests, the country for `country_pools` is determined by
// `location_strategy`.
// - `"random"`: Select a pool randomly.
// - `"dynamic_latency"`: Use round trip time to select the closest pool in
// default_pools (requires pool health checks).
// - `"proximity"`: Use the pools' latitude and longitude to select the closest
// pool using the Cloudflare PoP location for proxied requests or the location
// determined by `location_strategy` for non-proxied requests.
// - `"least_outstanding_requests"`: Select a pool by taking into consideration
// `random_steering` weights, as well as each pool's number of outstanding
// requests. Pools with more pending requests are weighted proportionately less
// relative to others.
// - `"least_connections"`: Select a pool by taking into consideration
// `random_steering` weights, as well as each pool's number of open connections.
// Pools with more open connections are weighted proportionately less relative to
// others. Supported for HTTP/1 and HTTP/2 connections.
// - `""`: Will map to `"geo"` if you use
// `region_pools`/`country_pools`/`pop_pools` otherwise `"off"`.
type LoadBalancerSteeringPolicy string
const (
LoadBalancerSteeringPolicyOff LoadBalancerSteeringPolicy = "off"
LoadBalancerSteeringPolicyGeo LoadBalancerSteeringPolicy = "geo"
LoadBalancerSteeringPolicyRandom LoadBalancerSteeringPolicy = "random"
LoadBalancerSteeringPolicyDynamicLatency LoadBalancerSteeringPolicy = "dynamic_latency"
LoadBalancerSteeringPolicyProximity LoadBalancerSteeringPolicy = "proximity"
LoadBalancerSteeringPolicyLeastOutstandingRequests LoadBalancerSteeringPolicy = "least_outstanding_requests"
LoadBalancerSteeringPolicyLeastConnections LoadBalancerSteeringPolicy = "least_connections"
LoadBalancerSteeringPolicyEmpty LoadBalancerSteeringPolicy = "\"\""
)
func (r LoadBalancerSteeringPolicy) IsKnown() bool {
switch r {
case LoadBalancerSteeringPolicyOff, LoadBalancerSteeringPolicyGeo, LoadBalancerSteeringPolicyRandom, LoadBalancerSteeringPolicyDynamicLatency, LoadBalancerSteeringPolicyProximity, LoadBalancerSteeringPolicyLeastOutstandingRequests, LoadBalancerSteeringPolicyLeastConnections, LoadBalancerSteeringPolicyEmpty:
return true
}
return false
}
// Configures load shedding policies and percentages for the pool.
type LoadShedding struct {
// The percent of traffic to shed from the pool, according to the default policy.
// Applies to new sessions and traffic without session affinity.
DefaultPercent float64 `json:"default_percent"`
// The default policy to use when load shedding. A random policy randomly sheds a
// given percent of requests. A hash policy computes a hash over the
// CF-Connecting-IP address and sheds all requests originating from a percent of
// IPs.
DefaultPolicy LoadSheddingDefaultPolicy `json:"default_policy"`
// The percent of existing sessions to shed from the pool, according to the session
// policy.
SessionPercent float64 `json:"session_percent"`
// Only the hash policy is supported for existing sessions (to avoid exponential
// decay).
SessionPolicy LoadSheddingSessionPolicy `json:"session_policy"`
JSON loadSheddingJSON `json:"-"`
}
// loadSheddingJSON contains the JSON metadata for the struct [LoadShedding]
type loadSheddingJSON struct {
DefaultPercent apijson.Field
DefaultPolicy apijson.Field
SessionPercent apijson.Field
SessionPolicy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LoadShedding) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loadSheddingJSON) RawJSON() string {
return r.raw
}
// The default policy to use when load shedding. A random policy randomly sheds a
// given percent of requests. A hash policy computes a hash over the
// CF-Connecting-IP address and sheds all requests originating from a percent of
// IPs.
type LoadSheddingDefaultPolicy string
const (
LoadSheddingDefaultPolicyRandom LoadSheddingDefaultPolicy = "random"
LoadSheddingDefaultPolicyHash LoadSheddingDefaultPolicy = "hash"
)
func (r LoadSheddingDefaultPolicy) IsKnown() bool {
switch r {
case LoadSheddingDefaultPolicyRandom, LoadSheddingDefaultPolicyHash:
return true
}
return false
}
// Only the hash policy is supported for existing sessions (to avoid exponential
// decay).
type LoadSheddingSessionPolicy string
const (
LoadSheddingSessionPolicyHash LoadSheddingSessionPolicy = "hash"
)
func (r LoadSheddingSessionPolicy) IsKnown() bool {
switch r {
case LoadSheddingSessionPolicyHash:
return true
}
return false
}
// Configures load shedding policies and percentages for the pool.
type LoadSheddingParam struct {
// The percent of traffic to shed from the pool, according to the default policy.
// Applies to new sessions and traffic without session affinity.
DefaultPercent param.Field[float64] `json:"default_percent"`
// The default policy to use when load shedding. A random policy randomly sheds a
// given percent of requests. A hash policy computes a hash over the
// CF-Connecting-IP address and sheds all requests originating from a percent of
// IPs.
DefaultPolicy param.Field[LoadSheddingDefaultPolicy] `json:"default_policy"`
// The percent of existing sessions to shed from the pool, according to the session
// policy.
SessionPercent param.Field[float64] `json:"session_percent"`
// Only the hash policy is supported for existing sessions (to avoid exponential
// decay).
SessionPolicy param.Field[LoadSheddingSessionPolicy] `json:"session_policy"`
}
func (r LoadSheddingParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Controls location-based steering for non-proxied requests. See `steering_policy`
// to learn how steering is affected.
type LocationStrategy struct {
// Determines the authoritative location when ECS is not preferred, does not exist
// in the request, or its GeoIP lookup is unsuccessful.
//
// - `"pop"`: Use the Cloudflare PoP location.
// - `"resolver_ip"`: Use the DNS resolver GeoIP location. If the GeoIP lookup is
// unsuccessful, use the Cloudflare PoP location.
Mode LocationStrategyMode `json:"mode"`
// Whether the EDNS Client Subnet (ECS) GeoIP should be preferred as the
// authoritative location.
//
// - `"always"`: Always prefer ECS.
// - `"never"`: Never prefer ECS.
// - `"proximity"`: Prefer ECS only when `steering_policy="proximity"`.
// - `"geo"`: Prefer ECS only when `steering_policy="geo"`.
PreferEcs LocationStrategyPreferEcs `json:"prefer_ecs"`
JSON locationStrategyJSON `json:"-"`
}
// locationStrategyJSON contains the JSON metadata for the struct
// [LocationStrategy]
type locationStrategyJSON struct {
Mode apijson.Field
PreferEcs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LocationStrategy) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r locationStrategyJSON) RawJSON() string {
return r.raw
}
// Determines the authoritative location when ECS is not preferred, does not exist
// in the request, or its GeoIP lookup is unsuccessful.
//
// - `"pop"`: Use the Cloudflare PoP location.
// - `"resolver_ip"`: Use the DNS resolver GeoIP location. If the GeoIP lookup is
// unsuccessful, use the Cloudflare PoP location.
type LocationStrategyMode string
const (
LocationStrategyModePop LocationStrategyMode = "pop"
LocationStrategyModeResolverIP LocationStrategyMode = "resolver_ip"
)
func (r LocationStrategyMode) IsKnown() bool {
switch r {
case LocationStrategyModePop, LocationStrategyModeResolverIP:
return true
}
return false
}
// Whether the EDNS Client Subnet (ECS) GeoIP should be preferred as the
// authoritative location.
//
// - `"always"`: Always prefer ECS.
// - `"never"`: Never prefer ECS.
// - `"proximity"`: Prefer ECS only when `steering_policy="proximity"`.
// - `"geo"`: Prefer ECS only when `steering_policy="geo"`.
type LocationStrategyPreferEcs string
const (
LocationStrategyPreferEcsAlways LocationStrategyPreferEcs = "always"
LocationStrategyPreferEcsNever LocationStrategyPreferEcs = "never"
LocationStrategyPreferEcsProximity LocationStrategyPreferEcs = "proximity"
LocationStrategyPreferEcsGeo LocationStrategyPreferEcs = "geo"
)
func (r LocationStrategyPreferEcs) IsKnown() bool {
switch r {
case LocationStrategyPreferEcsAlways, LocationStrategyPreferEcsNever, LocationStrategyPreferEcsProximity, LocationStrategyPreferEcsGeo:
return true
}
return false
}
// Controls location-based steering for non-proxied requests. See `steering_policy`
// to learn how steering is affected.
type LocationStrategyParam struct {
// Determines the authoritative location when ECS is not preferred, does not exist
// in the request, or its GeoIP lookup is unsuccessful.
//
// - `"pop"`: Use the Cloudflare PoP location.
// - `"resolver_ip"`: Use the DNS resolver GeoIP location. If the GeoIP lookup is
// unsuccessful, use the Cloudflare PoP location.
Mode param.Field[LocationStrategyMode] `json:"mode"`
// Whether the EDNS Client Subnet (ECS) GeoIP should be preferred as the
// authoritative location.
//
// - `"always"`: Always prefer ECS.
// - `"never"`: Never prefer ECS.
// - `"proximity"`: Prefer ECS only when `steering_policy="proximity"`.
// - `"geo"`: Prefer ECS only when `steering_policy="geo"`.
PreferEcs param.Field[LocationStrategyPreferEcs] `json:"prefer_ecs"`
}
func (r LocationStrategyParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Filter pool and origin health notifications by resource type or health status.
// Use null to reset.
type NotificationFilter struct {
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
Origin FilterOptions `json:"origin,nullable"`
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
Pool FilterOptions `json:"pool,nullable"`
JSON notificationFilterJSON `json:"-"`
}
// notificationFilterJSON contains the JSON metadata for the struct
// [NotificationFilter]
type notificationFilterJSON struct {
Origin apijson.Field
Pool apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *NotificationFilter) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r notificationFilterJSON) RawJSON() string {
return r.raw
}
// Filter pool and origin health notifications by resource type or health status.
// Use null to reset.
type NotificationFilterParam struct {
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
Origin param.Field[FilterOptionsParam] `json:"origin"`
// Filter options for a particular resource type (pool or origin). Use null to
// reset.
Pool param.Field[FilterOptionsParam] `json:"pool"`
}
func (r NotificationFilterParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type Origin struct {
// The IP address (IPv4 or IPv6) of the origin, or its publicly addressable
// hostname. Hostnames entered here should resolve directly to the origin, and not
// be a hostname proxied by Cloudflare. To set an internal/reserved address,
// virtual_network_id must also be set.
Address string `json:"address"`
// This field shows up only if the origin is disabled. This field is set with the
// time the origin was disabled.
DisabledAt time.Time `json:"disabled_at" format:"date-time"`
// Whether to enable (the default) this origin within the pool. Disabled origins
// will not receive traffic and are excluded from health checks. The origin will
// only be disabled for the current pool.
Enabled bool `json:"enabled"`
// The request header is used to pass additional information with an HTTP request.
// Currently supported header is 'Host'.
Header Header `json:"header"`
// A human-identifiable name for the origin.
Name string `json:"name"`
// The virtual network subnet ID the origin belongs in. Virtual network must also
// belong to the account.
VirtualNetworkID string `json:"virtual_network_id"`
// The weight of this origin relative to other origins in the pool. Based on the
// configured weight the total traffic is distributed among origins within the
// pool.
//
// - `origin_steering.policy="least_outstanding_requests"`: Use weight to scale the
// origin's outstanding requests.
// - `origin_steering.policy="least_connections"`: Use weight to scale the origin's
// open connections.
Weight float64 `json:"weight"`
JSON originJSON `json:"-"`
}
// originJSON contains the JSON metadata for the struct [Origin]
type originJSON struct {
Address apijson.Field
DisabledAt apijson.Field
Enabled apijson.Field
Header apijson.Field
Name apijson.Field
VirtualNetworkID apijson.Field
Weight apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Origin) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originJSON) RawJSON() string {
return r.raw
}
type OriginParam struct {
// The IP address (IPv4 or IPv6) of the origin, or its publicly addressable
// hostname. Hostnames entered here should resolve directly to the origin, and not
// be a hostname proxied by Cloudflare. To set an internal/reserved address,
// virtual_network_id must also be set.
Address param.Field[string] `json:"address"`
// Whether to enable (the default) this origin within the pool. Disabled origins
// will not receive traffic and are excluded from health checks. The origin will
// only be disabled for the current pool.
Enabled param.Field[bool] `json:"enabled"`
// The request header is used to pass additional information with an HTTP request.
// Currently supported header is 'Host'.
Header param.Field[HeaderParam] `json:"header"`
// A human-identifiable name for the origin.
Name param.Field[string] `json:"name"`
// The virtual network subnet ID the origin belongs in. Virtual network must also
// belong to the account.
VirtualNetworkID param.Field[string] `json:"virtual_network_id"`
// The weight of this origin relative to other origins in the pool. Based on the
// configured weight the total traffic is distributed among origins within the
// pool.
//
// - `origin_steering.policy="least_outstanding_requests"`: Use weight to scale the
// origin's outstanding requests.
// - `origin_steering.policy="least_connections"`: Use weight to scale the origin's
// open connections.
Weight param.Field[float64] `json:"weight"`
}
func (r OriginParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Configures origin steering for the pool. Controls how origins are selected for
// new sessions and traffic without session affinity.
type OriginSteering struct {
// The type of origin steering policy to use.
//
// - `"random"`: Select an origin randomly.
// - `"hash"`: Select an origin by computing a hash over the CF-Connecting-IP
// address.
// - `"least_outstanding_requests"`: Select an origin by taking into consideration
// origin weights, as well as each origin's number of outstanding requests.
// Origins with more pending requests are weighted proportionately less relative
// to others.
// - `"least_connections"`: Select an origin by taking into consideration origin
// weights, as well as each origin's number of open connections. Origins with
// more open connections are weighted proportionately less relative to others.
// Supported for HTTP/1 and HTTP/2 connections.
Policy OriginSteeringPolicy `json:"policy"`
JSON originSteeringJSON `json:"-"`
}
// originSteeringJSON contains the JSON metadata for the struct [OriginSteering]
type originSteeringJSON struct {
Policy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *OriginSteering) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originSteeringJSON) RawJSON() string {
return r.raw
}
// The type of origin steering policy to use.
//
// - `"random"`: Select an origin randomly.
// - `"hash"`: Select an origin by computing a hash over the CF-Connecting-IP
// address.
// - `"least_outstanding_requests"`: Select an origin by taking into consideration
// origin weights, as well as each origin's number of outstanding requests.
// Origins with more pending requests are weighted proportionately less relative
// to others.
// - `"least_connections"`: Select an origin by taking into consideration origin
// weights, as well as each origin's number of open connections. Origins with
// more open connections are weighted proportionately less relative to others.
// Supported for HTTP/1 and HTTP/2 connections.
type OriginSteeringPolicy string
const (
OriginSteeringPolicyRandom OriginSteeringPolicy = "random"
OriginSteeringPolicyHash OriginSteeringPolicy = "hash"
OriginSteeringPolicyLeastOutstandingRequests OriginSteeringPolicy = "least_outstanding_requests"
OriginSteeringPolicyLeastConnections OriginSteeringPolicy = "least_connections"
)
func (r OriginSteeringPolicy) IsKnown() bool {
switch r {
case OriginSteeringPolicyRandom, OriginSteeringPolicyHash, OriginSteeringPolicyLeastOutstandingRequests, OriginSteeringPolicyLeastConnections:
return true
}
return false
}
// Configures origin steering for the pool. Controls how origins are selected for
// new sessions and traffic without session affinity.
type OriginSteeringParam struct {
// The type of origin steering policy to use.
//
// - `"random"`: Select an origin randomly.
// - `"hash"`: Select an origin by computing a hash over the CF-Connecting-IP
// address.
// - `"least_outstanding_requests"`: Select an origin by taking into consideration
// origin weights, as well as each origin's number of outstanding requests.
// Origins with more pending requests are weighted proportionately less relative
// to others.
// - `"least_connections"`: Select an origin by taking into consideration origin
// weights, as well as each origin's number of open connections. Origins with
// more open connections are weighted proportionately less relative to others.
// Supported for HTTP/1 and HTTP/2 connections.
Policy param.Field[OriginSteeringPolicy] `json:"policy"`
}
func (r OriginSteeringParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Configures pool weights.
//
// - `steering_policy="random"`: A random pool is selected with probability
// proportional to pool weights.
// - `steering_policy="least_outstanding_requests"`: Use pool weights to scale each
// pool's outstanding requests.
// - `steering_policy="least_connections"`: Use pool weights to scale each pool's
// open connections.
type RandomSteering struct {
// The default weight for pools in the load balancer that are not specified in the
// pool_weights map.
DefaultWeight float64 `json:"default_weight"`
// A mapping of pool IDs to custom weights. The weight is relative to other pools
// in the load balancer.
PoolWeights interface{} `json:"pool_weights"`
JSON randomSteeringJSON `json:"-"`
}
// randomSteeringJSON contains the JSON metadata for the struct [RandomSteering]
type randomSteeringJSON struct {
DefaultWeight apijson.Field
PoolWeights apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RandomSteering) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r randomSteeringJSON) RawJSON() string {
return r.raw
}
// Configures pool weights.
//
// - `steering_policy="random"`: A random pool is selected with probability