當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Response.Error方法代碼示例

本文整理匯總了Golang中net/rpc.Response.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Response.Error方法的具體用法?Golang Response.Error怎麽用?Golang Response.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/rpc.Response的用法示例。


在下文中一共展示了Response.Error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	// If return err:
	// - io.EOF will became ErrShutdown or io.ErrUnexpectedEOF
	// - it will be returned as is for all pending calls
	// - client will be shutdown
	// So, return io.EOF as is, return *Error for all other errors.
	if err := c.dec.Decode(&c.resp); err != nil {
		if err == io.EOF {
			return err
		}
		return NewError(errInternal.Code, err.Error())
	}
	if c.resp.ID == nil {
		return c.resp.Error
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[*c.resp.ID]
	delete(c.pending, *c.resp.ID)
	c.mutex.Unlock()

	r.Error = ""
	r.Seq = *c.resp.ID
	if c.resp.Error != nil {
		r.Error = c.resp.Error.Error()
	}
	return nil
}
開發者ID:plumbum,項目名稱:rpc-codec,代碼行數:28,代碼來源:client.go

示例2: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[c.resp.Id]
	delete(c.pending, c.resp.Id)
	c.mutex.Unlock()

	r.Error = ""
	r.Seq = c.resp.Id
	if c.resp.Error != nil {
		x, ok := c.resp.Error.(string)
		if !ok {
			return fmt.Errorf("invalid error %v", c.resp.Error)
		}
		if x == "" {
			x = "unspecified error"
		}
		r.Error = x
	}
	return nil
}
開發者ID:anuvazhayil,項目名稱:HelloWorld_32bitOS,代碼行數:25,代碼來源:client.go

示例3: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	data, err := ReadRpc(c.rwc)
	if err != nil {
		return err
	}

	rsp := &PbRpcResponse{}
	err = proto.Unmarshal(data, rsp)
	if err != nil {
		return err
	}

	c.rsp = rsp

	r.Seq = rsp.GetId()
	if rsp.GetResult() == nil {
		if rsp.GetError() == "" {
			r.Error = "Unknown error occurred"
		} else {
			r.Error = rsp.GetError()
		}
	}

	return nil
}
開發者ID:krisis,項目名稱:pbrpc,代碼行數:25,代碼來源:client.go

示例4: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	msg := <-c.msgs
	c.resp.reset()
	if err := json.Unmarshal(msg.Body, &c.resp); err != nil {
		return err
	}
	seq, err := strconv.ParseUint(msg.CorrelationId, 0, 64)
	if err != nil {
		return err
	}
	c.Lock()
	r.Seq = seq
	r.ServiceMethod = c.pending[seq]
	delete(c.pending, seq)
	c.Unlock()

	r.Error = ""
	if c.resp.Error != nil || c.resp.Result == nil {
		x, ok := c.resp.Error.(string)
		if !ok {
			return fmt.Errorf("invalid error %v", c.resp.Error)
		}
		if x == "" {
			x = "unspecified error"
		}
		r.Error = x
	}
	return nil
}
開發者ID:pakudayo,項目名稱:mqrpc,代碼行數:29,代碼來源:client.go

示例5: ReadResponseHeader

func (c *HTTPCodec) ReadResponseHeader(resp *rpc.Response) (err error) {
	req := <-c.replyQueue
	resp.Seq = req.seq
	if req.err != nil {
		resp.Error = req.err.Error()
	} else {
		if e2 := req.codec.ReadStatus(req.reply, resp); e2 != nil {
			resp.Error = e2.Error()
		}
	}
	c.bodyQueue <- req
	return
}
開發者ID:areusch,項目名稱:httpcodec,代碼行數:13,代碼來源:codec.go

示例6: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(response *rpc.Response) error {
	if c.enableOneway {
		select {
		case ow := <-c.onewayRequests:
			response.ServiceMethod = ow.method
			response.Seq = ow.seq
			return nil
		case _ = <-c.twowayRequests:
		}
	}

	name, messageType, seq, err := c.conn.ReadMessageBegin()
	if err != nil {
		return err
	}
	response.ServiceMethod = name
	response.Seq = uint64(seq)
	if messageType == MessageTypeException {
		exception := &ApplicationException{}
		if err := DecodeStruct(c.conn, exception); err != nil {
			return err
		}
		response.Error = exception.String()
		return c.conn.ReadMessageEnd()
	}
	return nil
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:27,代碼來源:client.go

示例7: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) (err error) {

	c.bufs.Reset()

	// Read message
	parts, err := c.sock.RecvMultipart(0)
	if err != nil {
		return
	} else if len(parts) != 2 {
		err = errors.New("Unexpected number of parts to reply: " + fmt.Sprintf("%d", len(parts)))
		return
	}
	// log.Println("Client recieved multipart mesage:", Stringify(parts))

	hdr := parts[0]
	data := parts[1]

	c.bufs.body.SetBuf(data)

	h := new(Header)
	c.bufs.header.SetBuf(hdr)
	err = c.bufs.header.Unmarshal(h)
	if err != nil {
		return
	}

	r.Seq = h.GetId()
	r.ServiceMethod = h.GetServiceMethod()
	r.Error = h.GetError()

	// log.Println("Client recieved service response:", r)

	return nil
}
開發者ID:yanatan16,項目名稱:protorpc,代碼行數:34,代碼來源:client.go

示例8: StandardStatusDecoder

// Returns an error if response code != 200
func StandardStatusDecoder(resp *http.Response, rpcResp *rpc.Response) error {
	if resp.StatusCode != 200 {
		rpcResp.Error = fmt.Sprintf("Server returned HTTP response: %s", resp.Status)
	}

	return nil
}
開發者ID:areusch,項目名稱:httpcodec,代碼行數:8,代碼來源:basic.go

示例9: Error

func (self *RPCServer) Error(s string) error {
	var r rpc.Response
	r.ServiceMethod = self.lastServiceMethod
	r.Seq = self.lastSeq
	r.Error = s
	return self.codec.WriteResponse(&r, nil)
}
開發者ID:yonglehou,項目名稱:golang-distributed-filesystem,代碼行數:7,代碼來源:rpc.go

示例10: Send

func (self *RPCServer) Send(obj interface{}) error {
	var r rpc.Response
	r.ServiceMethod = self.lastServiceMethod
	r.Seq = self.lastSeq
	r.Error = ""
	return self.codec.WriteResponse(&r, obj)
}
開發者ID:yonglehou,項目名稱:golang-distributed-filesystem,代碼行數:7,代碼來源:rpc.go

示例11: ReadResponseHeader

func (codec *clientCodec) ReadResponseHeader(response *rpc.Response) (err error) {
	seq := <-codec.ready
	httpResponse := codec.responses[seq]

	if httpResponse.StatusCode < 200 || httpResponse.StatusCode >= 300 {
		return fmt.Errorf("request error: bad status code - %d", httpResponse.StatusCode)
	}

	respData, err := ioutil.ReadAll(httpResponse.Body)

	if err != nil {
		return err
	}

	httpResponse.Body.Close()

	resp := NewResponse(respData)

	if resp.Failed() {
		response.Error = fmt.Sprintf("%v", resp.Err())
	}

	codec.response = resp

	response.Seq = seq
	delete(codec.responses, seq)

	return nil
}
開發者ID:RezaDKhan,項目名稱:terraform,代碼行數:29,代碼來源:client.go

示例12: SendOkay

func (self *RPCServer) SendOkay() error {
	var r rpc.Response
	r.ServiceMethod = self.lastServiceMethod
	r.Seq = self.lastSeq
	r.Error = ""
	return self.codec.WriteResponse(&r, "OK")
}
開發者ID:yonglehou,項目名稱:golang-distributed-filesystem,代碼行數:7,代碼來源:rpc.go

示例13: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(rpcres *rpc.Response) error {
	f, err := read(c.r)
	if err != nil {
		return err
	}

	res := &Response{}
	if err := proto.Unmarshal(f, res); err != nil {
		return err
	}

	c.mutex.Lock()
	p, ok := c.pending[res.GetId()]
	if !ok {
		c.mutex.Unlock()
		return errors.New("invalid sequence number in response")
	}
	c.res = res
	delete(c.pending, res.GetId())
	c.mutex.Unlock()

	rpcres.Seq = p.Seq
	rpcres.ServiceMethod = p.ServiceMethod
	rpcres.Error = res.GetError()

	return nil
}
開發者ID:hujh,項目名稱:protorpc,代碼行數:27,代碼來源:client.go

示例14: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	var header wire.Header
	if err := readProto(c.r, &header); err != nil {
		return err
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[header.GetId()]
	delete(c.pending, header.GetId())
	c.mutex.Unlock()

	r.Error = ""
	r.Seq = header.GetId()
	if header.Error != nil {
		r.Error = header.GetError()
	}
	return nil
}
開發者ID:jwk000,項目名稱:protorpc,代碼行數:18,代碼來源:client.go

示例15: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	if err := c.readResponseHeader(&c.respHeader); err != nil {
		return err
	}

	r.Seq = c.respHeader.Id
	r.ServiceMethod = c.respHeader.GetMethod()
	r.Error = c.respHeader.Error
	return nil
}
開發者ID:Hellblazer,項目名稱:cockroach,代碼行數:10,代碼來源:client.go


注:本文中的net/rpc.Response.Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。