types.go 809 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package requests
  2. import "strconv"
  3. type Integer string
  4. func NewInteger(n int) Integer {
  5. return Integer(strconv.Itoa(n))
  6. }
  7. func (integer Integer) hasValue() bool {
  8. return integer != ""
  9. }
  10. func (integer Integer) getValue() (int, error) {
  11. return strconv.Atoi(string(integer))
  12. }
  13. type Boolean string
  14. func NewBoolean(bool bool) Boolean {
  15. return Boolean(strconv.FormatBool(bool))
  16. }
  17. func (boolean Boolean) hasValue() bool {
  18. return boolean != ""
  19. }
  20. func (boolean Boolean) getValue() (bool, error) {
  21. return strconv.ParseBool(string(boolean))
  22. }
  23. type Float string
  24. func NewFloat(f float64) Float {
  25. return Float(strconv.FormatFloat(f, 'f', 6, 64))
  26. }
  27. func (float Float) hasValue() bool {
  28. return float != ""
  29. }
  30. func (float Float) getValue() (float64, error) {
  31. return strconv.ParseFloat(string(float), 64)
  32. }