start reworking exporters to be more composable
This commit is contained in:
@ -1,13 +1,28 @@
|
||||
package code_location
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type CodeLocation struct {
|
||||
FilePath string
|
||||
FuncName string
|
||||
LineNumber int
|
||||
FilePath string
|
||||
FuncName string
|
||||
LineNumber int
|
||||
ColumnNumber int
|
||||
}
|
||||
|
||||
func FromStackTrace(...atDepth int) {
|
||||
func FromStackTrace(atDepth ...int) CodeLocation {
|
||||
skipLevelsInCallStack := 0
|
||||
|
||||
if len(atDepth) > 1 {
|
||||
skipLevelsInCallStack = atDepth[0]
|
||||
}
|
||||
pc, file, line, _ := runtime.Caller(1 + skipLevelsInCallStack)
|
||||
funcName := runtime.FuncForPC(pc).Name()
|
||||
|
||||
return CodeLocation{
|
||||
FilePath: file,
|
||||
LineNumber: line,
|
||||
FuncName: funcName,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user