And at the usage site, you can now just use standard encoding/json package
capabilities:
123456
rawPost,err:=json.Marshal(post)iferr!=nil{returnerr}// do stuff with rawPost
And now you can notice that tests do not pass. And the place that failed is
totally unrelevant. Long story short. Name of the original method was not
revealing any real intent: it was actually specific json representation for
usage with external API, but normal json.Marshal is used by this same
application for providing responses to its own HTTP clients.
Were the name a bit more intention-revealing, nobody would waste their time
on finding this out by trial and mistake:
1234
// should probably even sit in different packagefuncmarshalToExternalAPIFormat(postPost)([]byte,err){// ...}
And this is only a tip of the iceberg of how non-intention-revealing code can
trip you over.