Fix FileWithLineNum on windows

This commit is contained in:
Jinzhu 2020-06-07 18:27:12 +08:00
parent d11c424334
commit 31a0553b82
1 changed files with 3 additions and 3 deletions

View File

@ -3,8 +3,8 @@ package utils
import ( import (
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"path/filepath"
"reflect" "reflect"
"regexp"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -15,7 +15,7 @@ var gormSourceDir string
func init() { func init() {
_, file, _, _ := runtime.Caller(0) _, file, _, _ := runtime.Caller(0)
gormSourceDir = filepath.Dir(filepath.Dir(file)) gormSourceDir = regexp.MustCompile("utils.utils\\.go").ReplaceAllString(file, "")
} }
func FileWithLineNum() string { func FileWithLineNum() string {
@ -23,7 +23,7 @@ func FileWithLineNum() string {
_, file, line, ok := runtime.Caller(i) _, file, line, ok := runtime.Caller(i)
if ok && (!strings.HasPrefix(file, gormSourceDir) || strings.HasSuffix(file, "_test.go")) { if ok && (!strings.HasPrefix(file, gormSourceDir) || strings.HasSuffix(file, "_test.go")) {
return fmt.Sprintf("%v:%v", file, line) return file + ":" + strconv.FormatInt(int64(line), 10)
} }
} }
return "" return ""