Golang fmt.GoStringer type example

package fmt

GoStringer is implemented by any value that has a GoString method, which defines the Go syntax for that value. The GoString method is used to print values passed as an operand to a %#v format.

Golang fmt.GoStringer type usage example

 func deepPrint(b *bytes.Buffer, v reflect.Value) {
 i := v.Interface()
 t := v.Type()

 // GoStringer
 if g, ok := i.(fmt.GoStringer); ok {
 b.WriteString(g.GoString())
 return
 }
 ...

Reference :

http://golang.org/pkg/fmt/#GoStringer

Advertisement