2020-01-31 01:35:25 +03:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
2020-03-09 08:10:48 +03:00
|
|
|
"unicode"
|
2020-01-31 01:35:25 +03:00
|
|
|
)
|
|
|
|
|
2020-04-03 02:15:30 +03:00
|
|
|
var goSrcRegexp = regexp.MustCompile(`jinzhu/gorm(@.*)?/.*.go`)
|
|
|
|
var goTestRegexp = regexp.MustCompile(`jinzhu/gorm(@.*)?/.*test.go`)
|
2020-01-31 01:35:25 +03:00
|
|
|
|
|
|
|
func FileWithLineNum() string {
|
|
|
|
for i := 2; i < 15; i++ {
|
|
|
|
_, file, line, ok := runtime.Caller(i)
|
|
|
|
if ok && (!goSrcRegexp.MatchString(file) || goTestRegexp.MatchString(file)) {
|
|
|
|
return fmt.Sprintf("%v:%v", file, line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2020-03-09 08:10:48 +03:00
|
|
|
|
|
|
|
func IsChar(c rune) bool {
|
|
|
|
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
|
|
|
|
}
|