package code_location import ( "runtime" ) type CodeLocation struct { FilePath string FuncName string LineNumber int ColumnNumber 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, } }