main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package main
  2. import (
  3. "fmt"
  4. "hongze/mysteel_watch/core"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "sync"
  9. )
  10. // @BasePath /
  11. func main() {
  12. core.RunServe()
  13. }
  14. //检测指标文件
  15. func TestFileName(filePath string) {
  16. fmt.Println("filePath:", filePath)
  17. var newFilePath string
  18. defer func() {
  19. //重命名文件
  20. fmt.Println("newFilePath")
  21. fmt.Println(newFilePath)
  22. err := os.Rename(filePath, newFilePath)
  23. if err != nil {
  24. fmt.Println("os.Rename Err:" + err.Error())
  25. }
  26. }()
  27. var runMode string
  28. if strings.Contains(filePath, "debug") {
  29. runMode = "debug"
  30. } else {
  31. runMode = "release"
  32. }
  33. fmt.Println(runMode)
  34. //处理文件名
  35. dir, fp := filepath.Split(filePath)
  36. fmt.Println(dir)
  37. fmt.Println(fp)
  38. frequency := "年"
  39. var wg = sync.WaitGroup{}
  40. wg.Add(1)
  41. go func() {
  42. var frequencyStr string
  43. if strings.Contains(frequency, "日") {
  44. frequencyStr = "day"
  45. } else if strings.Contains(frequency, "周") {
  46. frequencyStr = "week"
  47. } else if strings.Contains(frequency, "月") {
  48. frequencyStr = "month"
  49. } else if strings.Contains(frequency, "年") {
  50. frequencyStr = "year"
  51. }
  52. if !strings.Contains(filePath, frequencyStr) {
  53. fpArr := strings.Split(fp, "_")
  54. for k, v := range fpArr {
  55. if k == 0 {
  56. newFilePath = v + "_" + frequencyStr
  57. } else {
  58. newFilePath = newFilePath + "_" + v
  59. }
  60. }
  61. }
  62. wg.Done()
  63. }()
  64. wg.Wait()
  65. newFilePath = dir + newFilePath
  66. }