2023-10-24 12:26:02 -04:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var (
|
|
|
|
errMissingRequestID = errors.New("missing RequestId field")
|
|
|
|
errMissingQuery = errors.New("missing Query field")
|
|
|
|
errMissingMessage = errors.New("missing Message field")
|
|
|
|
errMissingPubsubTopic = errors.New("missing PubsubTopic field")
|
2023-10-30 12:55:36 -04:00
|
|
|
errRequestIDMismatch = errors.New("requestID in response does not match request")
|
2023-10-24 12:26:02 -04:00
|
|
|
errMissingResponse = errors.New("missing Response field")
|
|
|
|
)
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
func (x *PushRpc) ValidateRequest() error {
|
2023-10-24 12:26:02 -04:00
|
|
|
if x.RequestId == "" {
|
|
|
|
return errMissingRequestID
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
if x.Request == nil {
|
2023-10-24 12:26:02 -04:00
|
|
|
return errMissingQuery
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
if x.Request.PubsubTopic == "" {
|
2023-10-24 12:26:02 -04:00
|
|
|
return errMissingPubsubTopic
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
if x.Request.Message == nil {
|
2023-10-24 12:26:02 -04:00
|
|
|
return errMissingMessage
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
return x.Request.Message.Validate()
|
2023-10-24 12:26:02 -04:00
|
|
|
}
|
|
|
|
|
2023-11-07 15:48:43 -04:00
|
|
|
func (x *PushRpc) ValidateResponse(requestID string) error {
|
2023-10-24 12:26:02 -04:00
|
|
|
if x.RequestId == "" {
|
|
|
|
return errMissingRequestID
|
|
|
|
}
|
|
|
|
|
|
|
|
if x.RequestId != requestID {
|
|
|
|
return errRequestIDMismatch
|
|
|
|
}
|
|
|
|
|
|
|
|
if x.Response == nil {
|
|
|
|
return errMissingResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|