int64.go 473 B

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