当前位置: 首页>>代码示例>>Golang>>正文


Golang Response.ServiceMethod方法代码示例

本文整理汇总了Golang中net/rpc.Response.ServiceMethod方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.ServiceMethod方法的具体用法?Golang Response.ServiceMethod怎么用?Golang Response.ServiceMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/rpc.Response的用法示例。


在下文中一共展示了Response.ServiceMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: WriteResponse

func (c *serverCodec) WriteResponse(response *rpc.Response, thriftStruct interface{}) error {
	c.mu.Lock()
	methodName := c.methodName[response.Seq]
	delete(c.methodName, response.Seq)
	c.mu.Unlock()
	response.ServiceMethod = methodName

	mtype := byte(MessageTypeReply)
	if response.Error != "" {
		mtype = MessageTypeException
		etype := int32(ExceptionInternalError)
		if strings.HasPrefix(response.Error, "rpc: can't find") {
			etype = ExceptionUnknownMethod
		}
		thriftStruct = &ApplicationException{response.Error, etype}
	}
	if err := c.protocol.WriteMessageBegin(c.transport, response.ServiceMethod, mtype, int32(response.Seq)); err != nil {
		return err
	}
	if err := EncodeStruct(c.transport, c.protocol, thriftStruct); err != nil {
		return err
	}
	if err := c.protocol.WriteMessageEnd(c.transport); err != nil {
		return err
	}
	if flusher, ok := c.transport.(Flusher); ok {
		return flusher.Flush()
	}
	return nil
}
开发者ID:jimmysawczuk,项目名称:go-thrift,代码行数:30,代码来源:server.go

示例11: writeResponse

func writeResponse(c *serverCodec) error {
	head := rpc.Response{}
	head.ServiceMethod = "TestFunc"
	head.Seq = 2
	head.Error = "call failed"

	body := testpb.Result{}
	body.Title = proto.String("www.zhihu.com")
	return c.WriteResponse(&head, &body)
}
开发者ID:ironzhang,项目名称:golang,代码行数:10,代码来源:codec_test.go

示例12: ReadResponseHeader

func (mux *multiplexCodec) ReadResponseHeader(res *rpc.Response) error {
	select {
	case err := <-mux.errorChan:
		return err
	case msg := <-mux.responseChan:
		res.ServiceMethod = responseMethod
		res.Seq = *msg.Sequence
	}
	return nil
}
开发者ID:croachrose,项目名称:discovery,代码行数:10,代码来源:multiplex.go

示例13: 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

示例14: ReadResponseHeader

func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	var rsp protorpcpb.Response
	if err := readFrame(c.rwc, &rsp); err != nil {
		return err
	}
	r.ServiceMethod = rsp.GetMethod()
	r.Seq = rsp.GetSeq()
	r.Error = rsp.GetErr()
	return nil
}
开发者ID:ironzhang,项目名称:golang,代码行数:10,代码来源:client.go

示例15: ReadResponseHeader

func (c *codec) ReadResponseHeader(r *rpc.Response) error {
	c.header = internal.Header{} // reset
	if err := c.decode(&c.header); err != nil {
		return err
	}

	r.ServiceMethod = c.header.Method
	r.Seq = c.header.SeqID
	r.Error = c.header.Error
	return nil
}
开发者ID:pascaldekloe,项目名称:colfer,代码行数:11,代码来源:rpc.go


注:本文中的net/rpc.Response.ServiceMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。