MCPcopy
hub / github.com/adonovan/gopl.io / Print

Function Print

ch12/methods/methods.go:17–27  ·  view source on GitHub ↗

!+print Print prints the method set of the value x.

(x interface{})

Source from the content-addressed store, hash-verified

15//!+print
16// Print prints the method set of the value x.
17func Print(x interface{}) {
18 v := reflect.ValueOf(x)
19 t := v.Type()
20 fmt.Printf("type %s\n", t)
21
22 for i := 0; i < v.NumMethod(); i++ {
23 methType := v.Method(i).Type()
24 fmt.Printf("func (%s) %s%s\n", t, t.Method(i).Name,
25 strings.TrimPrefix(methType.String(), "func"))
26 }
27}
28
29//!-print

Callers 2

ExamplePrintDurationFunction · 0.92
ExamplePrintReplacerFunction · 0.92

Calls 1

StringMethod · 0.45

Tested by 2

ExamplePrintDurationFunction · 0.74
ExamplePrintReplacerFunction · 0.74