When I want to override the '%v' format, I declare a String() method.
When I want to override the '%#v' format, I declare a GoString() method.
But there is nothing about '%+v'? There is no PlusStringer() method ?
Let's take the following exemple, the %v and %+v formatter prints the exact
same results. Which is annoying somehow..
```
package main
import ("fmt")
type page struct {
title string
body []byte
}
func (p *page) String() string {
return fmt.Sprint("{ ", p.title, " ", string(p.body), " }")
}
func main() {
const title = "helloworld"
const text = "Hello everyone"
p := &page{title: title, body: []byte(text)}
log.Printf("p = %v", p) // prints p = { helloworld Hello everyone }
log.Printf("p = %+v", p) // prints p = { helloworld Hello everyone }
log.Printf("p = %#v", p) // prints p = &main.page{title:"helloworld",
body:[]uint8{0x48, 0x65, 0x6c, [etc]
}
```
Any clue on how to adapt the String() method to print the fields names?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/2506ab0c-5558-4c72-8ad4-a8ad0006ea08o%40googlegroups.com.