Closed jterry75 closed 5 years ago
This looks good, but instead of returning interface{}, I would suggest returning a type of
interface {
GetBase() *MessageResponseBase
}
And then implement GetBase() on *MessageResponseBase to return itself.
This approach ensures that the functions return a response type (could still be the wrong one, of course), and it allows the caller of all these functions to copy the ActivityID field from the request rather than rely on each of the individual code paths to remember to do it.
This looks good, but instead of returning interface{}, I would suggest returning a type of ``` interface { GetBase() *MessageResponseBase }
And then implement GetBase() on *MessageResponseBase to return itself. This approach ensures that the functions return a response type (could still be the wrong one, of course), and it allows the caller of all these functions to copy the ActivityID field from the request rather than rely on each of the individual code paths to remember to do it.
I'm sure I am missing something but how does this help? Not all functions return a *MessageResponseBase
so having an interface with a GetBase()
method doesn't help me to eventually serialize the entire structure. It would only allow me to serialize the *MessageResponseBase
part of the structure.
Take a look at https://github.com/microsoft/hcsshim/blob/master/internal/gcs/protocol.go.
Got it thanks! PR Updated
34ths times the charm! @jstarks - PTAL
This change makes it easier for the rquest/response pattern to return a result or error. This is perferred over the w.Write and w.Error pattern where a response must be written and then an early return. This makes the code easier to read and control flow easier to understand.