int32.go 473 B

123456789101112131415161718192021222324252627282930313233343536
  1. package optional
  2. type Int32 struct {
  3. isSet bool
  4. value int32
  5. }
  6. func NewInt32(value int32) Int32 {
  7. return Int32{
  8. true,
  9. value,
  10. }
  11. }
  12. // EmptyInt32 returns a new Int32 that does not have a value set.
  13. func EmptyInt32() Int32 {
  14. return Int32{
  15. false,
  16. 0,
  17. }
  18. }
  19. func (i Int32) IsSet() bool {
  20. return i.isSet
  21. }
  22. func (i Int32) Value() int32 {
  23. return i.value
  24. }
  25. func (i Int32) Default(defaultValue int32) int32 {
  26. if i.isSet {
  27. return i.value
  28. }
  29. return defaultValue
  30. }