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.

51 lines
1.0 KiB

2 years ago
  1. package util
  2. import "os"
  3. //import "github.com/EDDYCJY/go-gin-example/pkg/setting"
  4. const EXT = ".xlsx"
  5. // GetExcelFullUrl get the full access path of the Excel file
  6. func GetExcelFullUrl(name string) string {
  7. return "." + "/" + name
  8. }
  9. // GetExcelPath get the relative save path of the Excel file
  10. func GetExcelPath() string {
  11. //return setting.AppSetting.ExportSavePath
  12. return "excel/"
  13. }
  14. // GetExcelFullPath Get the full save path of the Excel file
  15. func GetExcelFullPath() string {
  16. return "./" + GetExcelPath()
  17. }
  18. // IsNotExistMkDir create a directory if it does not exist
  19. func IsNotExistMkDir(src string) error {
  20. if notExist := CheckNotExist(src); notExist == true {
  21. if err := MkDir(src); err != nil {
  22. return err
  23. }
  24. }
  25. return nil
  26. }
  27. // CheckNotExist check if the file exists
  28. func CheckNotExist(src string) bool {
  29. _, err := os.Stat(src)
  30. return os.IsNotExist(err)
  31. }
  32. // MkDir create a directory
  33. func MkDir(src string) error {
  34. err := os.MkdirAll(src, os.ModePerm)
  35. if err != nil {
  36. return err
  37. }
  38. return nil
  39. }