func (c Call) marshaler() tmsg.Marshaler { result := tmsg.Marshaler(nil) if c.Headers != nil && c.Headers[marshaling.ContentTypeHeader] != "" { result = marshaling.Marshaler(c.Headers[marshaling.ContentTypeHeader]) } if result == nil { result = tmsg.ProtoMarshaler() } return result }
func responseFromRequest(req Request, body interface{}) Response { rsp := NewResponse() rsp.SetId(req.Id()) if body != nil { rsp.SetBody(body) ct := req.Headers()[marshaling.AcceptHeader] marshaler := marshaling.Marshaler(ct) if marshaler == nil { // Fall back to JSON marshaler = marshaling.Marshaler(marshaling.JSONContentType) } if marshaler == nil { log.Error(req, "[Mercury] No marshaler for response %s: %s", rsp.Id(), ct) } else if err := marshaler.MarshalBody(rsp); err != nil { log.Error(req, "[Mercury] Failed to marshal response %s: %v", rsp.Id(), err) } } return rsp }