ax(node): replace prose comments with usage examples in protocol.go
ValidateResponse, ParseResponse, and GetProtocolErrorCode had comments that restated the function signature in prose — violating AX Principle 2 which requires comments to show concrete call-site usage, not descriptions. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
5843720a49
commit
7a87f2e633
1 changed files with 4 additions and 3 deletions
|
|
@ -60,12 +60,13 @@ func (h *ResponseHandler) ParseResponse(resp *Message, expectedType MessageType,
|
|||
// DefaultResponseHandler is the default response handler instance.
|
||||
var DefaultResponseHandler = &ResponseHandler{}
|
||||
|
||||
// ValidateResponse is a convenience function using the default handler.
|
||||
// if err := ValidateResponse(resp, MsgPong); err != nil { return 0, err }
|
||||
func ValidateResponse(resp *Message, expectedType MessageType) error {
|
||||
return DefaultResponseHandler.ValidateResponse(resp, expectedType)
|
||||
}
|
||||
|
||||
// ParseResponse is a convenience function using the default handler.
|
||||
// var stats StatsPayload
|
||||
// if err := ParseResponse(resp, MsgStats, &stats); err != nil { return nil, err }
|
||||
func ParseResponse(resp *Message, expectedType MessageType, target interface{}) error {
|
||||
return DefaultResponseHandler.ParseResponse(resp, expectedType, target)
|
||||
}
|
||||
|
|
@ -76,7 +77,7 @@ func IsProtocolError(err error) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
// GetProtocolErrorCode returns the error code if err is a ProtocolError, otherwise returns 0.
|
||||
// code := GetProtocolErrorCode(err) // 0 when err is not a ProtocolError
|
||||
func GetProtocolErrorCode(err error) int {
|
||||
if pe, ok := err.(*ProtocolError); ok {
|
||||
return pe.Code
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue