-
Notifications
You must be signed in to change notification settings - Fork 33
/
utils.go
48 lines (35 loc) · 894 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package util
import (
"fmt"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// HandlePanic helper method to handle panics
func HandlePanic(name string, err *error) {
if r := recover(); r != nil {
logger.Warnf("%s: PANIC Occurred : %v\n", name, r)
// todo: useful for debugging
logger.Debugf("StackTrace: %s", debug.Stack())
if err != nil {
*err = fmt.Errorf("%v", r)
}
}
}
// URLStringToFilePath convert fileURL to file path
func URLStringToFilePath(fileURL string) (string, bool) {
if strings.HasPrefix(fileURL, "file://") {
filePath := fileURL[7:]
if runtime.GOOS == "windows" {
if strings.HasPrefix(filePath, "/") {
filePath = filePath[1:]
}
filePath = filepath.FromSlash(filePath)
}
filePath = strings.Replace(filePath, "%20", " ", -1)
return filePath, true
}
return "", false
}