uint8.go 473 B

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