path.go 653 B

123456789101112131415161718192021222324252627282930
  1. package common
  2. import (
  3. "lzyd-user-api/utils"
  4. "path"
  5. "time"
  6. )
  7. func GetImagePath(filename string) string {
  8. if len(filename) > 0 {
  9. savePath := path.Join(ImageInfo.BasePath, ImageInfo.OutputDir)
  10. savePath = path.Join(savePath, time.Now().Format("2006-01"))
  11. if err := utils.IsNotExistMkDirAll(savePath); err == nil {
  12. suffix := path.Ext(filename)
  13. if len(suffix) == 0 {
  14. suffix = ".jpg"
  15. }
  16. return path.Join(savePath, utils.RandImageName(12)+suffix)
  17. }
  18. }
  19. return ""
  20. }
  21. func GetImageURLFromPath(path string) string {
  22. if len(path) > 0 {
  23. length := len(ImageInfo.BasePath)
  24. return ImageInfo.PrefixURL + path[length:]
  25. }
  26. return ""
  27. }