utils.go 915 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/go-resty/resty/v2"
  5. uuid "github.com/satori/go.uuid"
  6. "strings"
  7. )
  8. func AllBlank(str ...string) bool {
  9. for _, s := range str {
  10. if !HasBlank(s) {
  11. return false
  12. }
  13. }
  14. return true
  15. }
  16. func HasBlank(str ...string) bool {
  17. for _, s := range str {
  18. if strings.Trim(s, " ") == "" {
  19. return true
  20. }
  21. }
  22. return false
  23. }
  24. func HasText(str ...string) bool {
  25. for _, s := range str {
  26. if strings.Trim(s, " ") != "" {
  27. return true
  28. }
  29. }
  30. return false
  31. }
  32. func GetUUID() string {
  33. return uuid.NewV4().String()
  34. }
  35. func SimpleUUID() string {
  36. return strings.ReplaceAll(GetUUID(), "-", "")
  37. }
  38. func ResponseStatusError(url string, resp *resty.Response) error {
  39. if resp.Body() != nil && len(resp.Body()) != 0 {
  40. return fmt.Errorf("URL: %s Status: %d %s\n", url, resp.StatusCode(), resp.Body())
  41. } else {
  42. return fmt.Errorf("URL: %s Status: %s\n", url, resp.Status())
  43. }
  44. }