Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug/gdebug: CallerPackage() function, incorrect package name handling #3756

Closed
ghost opened this issue Sep 3, 2024 · 0 comments · Fixed by #3771
Closed

debug/gdebug: CallerPackage() function, incorrect package name handling #3756

ghost opened this issue Sep 3, 2024 · 0 comments · Fixed by #3771
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@ghost
Copy link

ghost commented Sep 3, 2024

Go version

go 1.18

GoFrame version

2.71

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

// CallerPackage returns the package name of the caller.
func CallerPackage() string {
	function, _, _ := Caller()

	//备注, 这里假设function值为 "github.com/gogf/gf/v2/test/gtest.C"
	function = "github.com/gogf/gf/v2/test/gtest.C"

	indexSplit := strings.LastIndexByte(function, '/')
	if indexSplit == -1 {
		return function[:strings.IndexByte(function, '.')]
	} else {
		leftPart := function[:indexSplit+1]
		rightPart := function[indexSplit+1:]
		//indexDot := strings.IndexByte(function, '.') //这行是原先代码的. 感觉逻辑有误
		indexDot := strings.IndexByte(rightPart, '.') //备注, 这里应该是对"gtest.C"操作, 而不是function吧?
		//rightPart = rightPart[:indexDot-1] //这行是原先代码的. 感觉逻辑有误,rightPart的目的是为了取到 "gtest"
		rightPart = rightPart[:indexDot]
		return leftPart + rightPart
	}
}

What did you see happen?

上面中文有备注, 应该是逻辑有误, 只不过恰巧代码结果也是"github.com/gogf/gf/v2/test/gtest"

What did you expect to see?

.

@ghost ghost added the bug It is confirmed a bug, but don't worry, we'll handle it. label Sep 3, 2024
@Issues-translate-bot Issues-translate-bot changed the title os/gdebug: CallerPackage()函数, 逻辑有误. os/gdebug: CallerPackage() function, logic is wrong. Sep 3, 2024
@gqcn gqcn self-assigned this Sep 13, 2024
@gqcn gqcn changed the title os/gdebug: CallerPackage() function, logic is wrong. debug/gdebug: CallerPackage() function, incorrect package name handling Sep 13, 2024
@gogf gogf deleted a comment from Issues-translate-bot Sep 13, 2024
gqcn added a commit that referenced this issue Sep 13, 2024
@gqcn gqcn added the done This issue is done, which may be release in next version. label Sep 13, 2024
@gqcn gqcn closed this as completed Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant