You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
464 B

  1. package util
  2. import (
  3. "strconv"
  4. )
  5. func ParseInt(text string, defaultValue int) int {
  6. count, parseError := strconv.ParseInt(text, 10, 64)
  7. if parseError != nil {
  8. if len(text) > 0 {
  9. return 0
  10. }
  11. return defaultValue
  12. }
  13. return int(count)
  14. }
  15. func ParseUint64(text string, defaultValue uint64) uint64 {
  16. count, parseError := strconv.ParseUint(text, 10, 64)
  17. if parseError != nil {
  18. if len(text) > 0 {
  19. return 0
  20. }
  21. return defaultValue
  22. }
  23. return count
  24. }