Adjust trim package name strategy

This commit is contained in:
RPRX 2020-12-05 04:39:58 +00:00 committed by GitHub
parent 32e7cd80e8
commit 5a43fa750d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,13 +36,17 @@ func (err *Error) WithPathObj(obj interface{}) *Error {
}
func (err *Error) pkgPath() string {
if err.pathObj != nil {
if p := reflect.TypeOf(err.pathObj).PkgPath(); !strings.HasPrefix(p, "main") {
return p[trim:]
}
}
if err.pathObj == nil {
return ""
}
path := reflect.TypeOf(err.pathObj).PkgPath()
for i := 0; i < len(path); i++ {
if path[i] == '/' {
return path[trim:]
}
}
return path
}
// Error implements error.Error().
func (err *Error) Error() string {