diff --git a/debug/gdebug/gdebug_caller.go b/debug/gdebug/gdebug_caller.go index fa9bb2115..b2e2577f3 100644 --- a/debug/gdebug/gdebug_caller.go +++ b/debug/gdebug/gdebug_caller.go @@ -52,7 +52,7 @@ func Caller(skip ...int) (function string, path string, line int) { // CallerWithFilter returns the function name and the absolute file path along with // its line number of the caller. // -// The parameter is used to filter the path of the caller. +// The parameter `filter` is used to filter the path of the caller. func CallerWithFilter(filter string, skip ...int) (function string, path string, line int) { var ( number = 0 @@ -166,12 +166,12 @@ func CallerFileLineShort() string { return fmt.Sprintf(`%s:%d`, filepath.Base(path), line) } -// FuncPath returns the complete function path of given . +// FuncPath returns the complete function path of given `f`. func FuncPath(f interface{}) string { return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() } -// FuncName returns the function name of given . +// FuncName returns the function name of given `f`. func FuncName(f interface{}) string { path := FuncPath(f) if path == "" { diff --git a/debug/gdebug/gdebug_stack.go b/debug/gdebug/gdebug_stack.go index a9c0a1e9c..1a2f0c37d 100644 --- a/debug/gdebug/gdebug_stack.go +++ b/debug/gdebug/gdebug_stack.go @@ -28,7 +28,7 @@ func Stack(skip ...int) string { // StackWithFilter returns a formatted stack trace of the goroutine that calls it. // It calls runtime.Stack with a large enough buffer to capture the entire trace. // -// The parameter is used to filter the path of the caller. +// The parameter `filter` is used to filter the path of the caller. func StackWithFilter(filter string, skip ...int) string { return StackWithFilters([]string{filter}, skip...) } @@ -36,7 +36,7 @@ func StackWithFilter(filter string, skip ...int) string { // StackWithFilters returns a formatted stack trace of the goroutine that calls it. // It calls runtime.Stack with a large enough buffer to capture the entire trace. // -// The parameter is a slice of strings, which are used to filter the path of the +// The parameter `filters` is a slice of strings, which are used to filter the path of the // caller. // // TODO Improve the performance using debug.Stack. diff --git a/debug/gdebug/gdebug_testdata.go b/debug/gdebug/gdebug_testdata.go index e3d2dadad..c87f24b13 100644 --- a/debug/gdebug/gdebug_testdata.go +++ b/debug/gdebug/gdebug_testdata.go @@ -7,12 +7,13 @@ package gdebug import ( + "io/ioutil" "path/filepath" ) // TestDataPath retrieves and returns the testdata path of current package, // which is used for unit testing cases only. -// The optional parameter specifies the its sub-folders/sub-files, +// The optional parameter `names` specifies the sub-folders/sub-files, // which will be joined with current system separator and returned with the path. func TestDataPath(names ...string) string { path := CallerDirectory() + string(filepath.Separator) + "testdata" @@ -21,3 +22,15 @@ func TestDataPath(names ...string) string { } return path } + +// TestDataContent retrieves and returns the file content for specified testdata path of current package +func TestDataContent(names ...string) string { + path := TestDataPath(names...) + if path != "" { + data, err := ioutil.ReadFile(path) + if err == nil { + return string(data) + } + } + return "" +}