utils.go 879 B

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