Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Reflection-Get-source/Go/reflection-get-source.go
Normal file
22
Task/Reflection-Get-source/Go/reflection-get-source.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func someFunc() {
|
||||
fmt.Println("someFunc called")
|
||||
}
|
||||
|
||||
func main() {
|
||||
pc := reflect.ValueOf(someFunc).Pointer()
|
||||
f := runtime.FuncForPC(pc)
|
||||
name := f.Name()
|
||||
file, line := f.FileLine(pc)
|
||||
fmt.Println("Name of function :", name)
|
||||
fmt.Println("Name of file :", path.Base(file))
|
||||
fmt.Println("Line number :", line)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue