Naming convention for a struct that writes other structs to an io.Writer?

61 views
Skip to first unread message

Amit Lavon

unread,
Feb 25, 2021, 4:53:51 AM2/25/21
to golang-nuts
Writer? Encoder? Putter?

I am creating a library for writing certain data objects (hence MyStruct) to an io.Writer. I was trying to find how Go's standard library typically names interfaces like that so that I could stick to the conventional naming.
Seems that the JSON package uses Encoder and Encode. The CSV package uses Writer and Write. I see that the Encode naming is more common in the encoding/... packages, but these usually encode general values (interface{}) and not specific types (like MyStruct).

What would be an idiomatic naming/API design for a case like this?
What makes CSV a writer and JSON an encoder?
Reply all
Reply to author
Forward
0 new messages