| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
import ( |
| 10 |
"reflect" |
| 11 |
"runtime" |
| 12 |
) |
| 13 |
|
| 14 |
func f(n int) int { |
| 15 |
return n % 2 |
| 16 |
} |
| 17 |
|
| 18 |
func g(n int) int { |
| 19 |
return f(n) |
| 20 |
} |
| 21 |
|
| 22 |
func name(fn any) (res string) { |
| 23 |
return runtime.FuncForPC(uintptr(reflect.ValueOf(fn).Pointer())).Name() |
| 24 |
} |
| 25 |
|
| 26 |
func main() { |
| 27 |
println(name(f)) |
| 28 |
println(name(g)) |
| 29 |
} |