本文整理匯總了Golang中protocol.Response類的典型用法代碼示例。如果您正苦於以下問題:Golang Response類的具體用法?Golang Response怎麽用?Golang Response使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Response類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteResponse
func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *protocol.Response) error {
data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}
if len(data) >= MAX_RESPONSE_SIZE {
pointCount := len(response.Series.Points)
firstHalfPoints := response.Series.Points[:pointCount]
secondHalfPoints := response.Series.Points[pointCount:]
response.Series.Points = firstHalfPoints
err := self.WriteResponse(conn, response)
if err != nil {
return err
}
response.Series.Points = secondHalfPoints
return self.WriteResponse(conn, response)
}
buff := bytes.NewBuffer(make([]byte, 0, len(data)+8))
binary.Write(buff, binary.LittleEndian, uint32(len(data)))
_, err = conn.Write(append(buff.Bytes(), data...))
if err != nil {
log.Error("error writing response: %s", err)
return err
}
return nil
}
示例2: WriteResponse
func (self *ProtobufRequestHandler) WriteResponse(conn net.Conn, response *protocol.Response) error {
data, err := response.Encode()
if err != nil {
log.Error("error encoding response: %s", err)
return err
}
err = binary.Write(conn, binary.LittleEndian, uint32(len(data)))
if err != nil {
log.Error("error writing response length: %s", err)
return err
}
_, err = conn.Write(data)
return err
}