How to implement Reader Writer interface for user defined type in GoLang

I am trying to achieve below functionality and planning to implement my new type as a ReadWriter interface for extensibility and ease of testing.

  1. Reader :- Reader is expected to use http package and call web API that will return response in JSON format. I am planning to implementing this as a reader interface. While doing this I have some doubts :-
    A. Is it correct to implement above functionality as a reader interface ?
    B. We need to send byte slice that is allocated but what should be the size of this slice? How to decide it?
  2. Writer :- Writer is expected to unmarshal byte slice to a user defined type. While doing this I have some doubts :-
    A. Is it correct to implement above functionality as a writer interface ?
    B. As writer interface needs to return number of bytes written, how can I found how many bytes are unmarshalled ?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.