Course you could think of something like:
func (ms MyStruct) String() string {
b, err := json.Marshal(ms)
if err != nil {
panic(err)
}
return string(b)
}
but this is not really performant, since you're calling the JSON parser for real (however, any empty field marked as "omitempty" in its tag would effectively be omitted).
The only other way to go I can think of right now is to use reflection --> tags, and then choosing what you do according to what you encounter. But again, this is quite greedy (speaking of execution time).
Why don't you just use spew? Course this is greedy as well but at least you don't get to re-invent the wheel.
Maybe if you state your need in a clearer way, we can help you better? :)
Keep GoIng ;)