How request fields and zero values work
mainAll request parameters are wrapped in a generic Field type. This allows the SDK to distinguish between a zero value (like 0, false, or "") and a field that was omitted or explicitly set to null.
- Use
cloudflare.F[T](value)to set a value. - Use
cloudflare.Null[T]()to explicitly send anullvalue. - Use
cloudflare.Raw[T](value)to send a value that doesn't strictly match the expected type (e.g., sending a float where an int is expected). - Helpers like
String(),Int(), andFloat()are also available.
params := FooParams{
Name: cloudflare.F("hello"),
// Explicitly send `"description": null`
Description: cloudflare.Null[string](),
Point: cloudflare.F(cloudflare.Point{
X: cloudflare.Int(0),
Y: cloudflare.Int(1),
// In cases where the API specifies a given type,
// but you want to send something else, use `Raw`:
Z: cloudflare.Raw[int64](0.01), // sends a float
},
}