Standard library / runtime
runtime.Func.FileLine()
Resolves source file and line for a PC within the function. Debug information may vary with the build. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (f *Func) FileLine(pc uintptr) (file string, line int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pc | uintptr | Program counter within the represented function. |
Return Value
(file string, line int)
Source file and line corresponding to the supplied program counter.
Working Example
Example Snippetgo
package main
import ( "fmt" "runtime" "strings")
func main() { pc, _, _, _ := runtime.Caller(0) f := runtime.FuncForPC(pc) file, line := f.FileLine(pc) fmt.Println(strings.HasSuffix(file, "main.go") && line > 0)}