openai/openai-go
Publicmirrored from https://github.com/openai/openai-goAvailable
internal/param/field.go
27lines · modecode
| 1 | package param |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | type FieldLike interface{ field() } |
| 6 | |
| 7 | // Field is a wrapper used for all values sent to the API, |
| 8 | // to distinguish zero values from null or omitted fields. |
| 9 | // |
| 10 | // It also allows sending arbitrary deserializable values. |
| 11 | // |
| 12 | // To instantiate a Field, use the helpers exported from |
| 13 | // the package root: `F()`, `Null()`, `Raw()`, etc. |
| 14 | type Field[T any] struct { |
| 15 | FieldLike |
| 16 | Value T |
| 17 | Null bool |
| 18 | Present bool |
| 19 | Raw any |
| 20 | } |
| 21 | |
| 22 | func (f Field[T]) String() string { |
| 23 | if s, ok := any(f.Value).(fmt.Stringer); ok { |
| 24 | return s.String() |
| 25 | } |
| 26 | return fmt.Sprintf("%v", f.Value) |
| 27 | } |
| 28 | |