tools.go 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package service
  2. import (
  3. "os"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "go-common/library/log"
  8. )
  9. const pathPerm = 0775
  10. // uniqueFolderPath Unique Folder Path
  11. func (s *Service) uniqueFolderPath(path string) (uniquePath string, err error) {
  12. uniquePath = path + strconv.Itoa(time.Now().Nanosecond()) + "/"
  13. for {
  14. var isExists bool
  15. if isExists, err = exists(uniquePath); err != nil {
  16. return
  17. }
  18. if !isExists {
  19. if err = os.MkdirAll(uniquePath, pathPerm); err != nil {
  20. uniquePath = ""
  21. log.Error("Create err ... (%v)", err)
  22. return
  23. }
  24. break
  25. } else {
  26. uniquePath = path + strconv.Itoa(time.Now().Nanosecond()) + "/"
  27. }
  28. }
  29. return
  30. }
  31. // getSessionInCookie get session
  32. func (s *Service) getSessionInCookie(cookie string) (session string) {
  33. cookieStr := strings.Split(cookie, ";")
  34. for _, value := range cookieStr {
  35. strt := strings.TrimSpace(value)
  36. strs := strings.Split(strt, "=")
  37. if strs[0] == "_AJSESSIONID" {
  38. session = strs[1]
  39. return
  40. }
  41. }
  42. return
  43. }