package common import ( "fmt" "github.com/google/uuid" "log" "os" "path/filepath" "strings" ) // GenerateUUID 生成UUID func GenerateUUID() string { UUID, err := uuid.NewRandom() if err != nil { _ = fmt.Sprintf("UUID generate err:%s", err.Error()) return "" } return strings.Replace(UUID.String(), "-", "", -1) } // CheckFile 检查文件扩展名 func CheckFile(fileName string) string { fileNames := []string{"json", "txt", "wav", "npy", "xlsx", "xls", "sql"} for _, temp := range fileNames { if strings.HasSuffix(strings.ToLower(fileName), temp) { return temp } } return "" } // GetCurrentAbPathByExecutable 获取当前执行程序所在的绝对路径 func GetCurrentAbPathByExecutable() string { exePath, err := os.Executable() if err != nil { log.Fatal(err) } res, _ := filepath.EvalSymlinks(filepath.Dir(exePath)) return res }