How request fields and zero values work
mainThe SDK uses a generic Field[T] type for all request parameters. This distinguishes between a zero value (like 0, false, or "") and a field that is null or omitted.
- To send a value: Use
opencode.F(value)or specific helpers likeopencode.String(),opencode.Int(), oropencode.Float(). - To send
null: Useopencode.Null[T](). - To send a nonconforming type: Use
opencode.Raw[T](value)(e.g., sending a float where anint64is expected).
Any field not specified in the params struct is not sent in the request.
params := FooParams{
Name: opencode.F("hello"),
// Explicitly send `"description": null`
Description: opencode.Null[string](),
Point: opencode.F(opencode.Point{
X: opencode.Int(0),
Y: opencode.Int(1),
// In cases where the API specifies a given type, but you want to send something else:
Z: opencode.Raw[int64](0.01), // sends a float
}),
}