field.go 599 B

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