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


Golang Request.ServiceMethod方法代码示例

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


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

示例1: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(request *rpc.Request) error {
	name, messageType, seq, err := c.protocol.ReadMessageBegin(c.transport)
	if err != nil {
		return err
	}
	if messageType != MessageTypeCall { // Currently don't support one way
		return errors.New("thrift: expected Call message type")
	}

	// TODO: should use a limited size cache for the nameCache to avoid a possible
	//       memory overflow from nefarious or broken clients
	newName := c.nameCache[name]
	if newName == "" {
		newName = CamelCase(name)
		if !strings.ContainsRune(newName, '.') {
			newName = "Thrift." + newName
		}
		c.nameCache[name] = newName
	}

	c.mu.Lock()
	c.methodName[uint64(seq)] = name
	c.mu.Unlock()

	request.ServiceMethod = newName
	request.Seq = uint64(seq)

	return nil
}
开发者ID:jimmysawczuk,项目名称:go-thrift,代码行数:29,代码来源:server.go

示例2: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
	var sz uint16
	err := binary.Read(c.c, binary.BigEndian, &sz)
	if err != nil {
		return err
	}
	log.Print("sz: ", sz)
	raw_message := make([]byte, sz)
	n, err := io.ReadFull(c.c, raw_message)
	if err != nil || n != int(sz) {
		return err
	}
	c.req.reset()
	log.Print("raw_message: ", string(raw_message))
	err = json.Unmarshal(raw_message, &(c.req))
	log.Print("after unmarshal: ", c.req)
	if err != nil {
		log.Print("err: ", err)
		return err
	}
	r.ServiceMethod = c.req.Method
	c.mutex.Lock()
	c.seq++
	c.pending[c.seq] = c.req.Id
	c.req.Id = nil
	r.Seq = c.seq
	c.mutex.Unlock()
	return nil
}
开发者ID:cjl3080434008,项目名称:redis-land-go,代码行数:29,代码来源:custom_jsonrpc.go

示例3: Call

func (this *Client) Call(method string, arg interface{}, reply interface{}) (e error) {

	clientConn := new(clientConn)
	clientConn.rest()
	this.codec = NewClientCodec(clientConn)
	req := rpc.Request{}
	req.Seq = defaultIdCreator.NewId()
	req.ServiceMethod = method
	e = this.codec.WriteRequest(&req, arg)
	buffer := bytes.NewBuffer(clientConn.Data)
	resp, e := http.Post(this.addr, "application/json", buffer)
	if e != nil {
		return
	}
	clientConn.SetResponse(resp)
	tmp := &rpc.Response{}
	e = this.codec.ReadResponseHeader(tmp)
	if e != nil {
		return
	}
	e = this.codec.ReadResponseBody(reply)
	if e != nil {
		return
	}
	fmt.Println(string(clientConn.Data))
	return
}
开发者ID:juxuny,项目名称:go,代码行数:27,代码来源:Client.go

示例4: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(req *rpc.Request) error {
	line, err := c.r.ReadSlice('\n')
	if err != nil {
		return err
	}
	if len(line) <= 2 {
		return fmt.Errorf("incomplete request header")
	}
	llen, err := strconv.Atoi(string(line[:len(line)-2])) // ignore trailing CRLF
	if err != nil {
		return err
	}
	if llen < 0 {
		return fmt.Errorf("negative request header length")
	}
	b := make([]byte, llen+2) // 2 bytes for trailing CRLF
	_, err = io.ReadFull(c.r, b)
	if err != nil {
		return err
	}

	var header struct {
		Method string `json:"interface_name"`
		//Seq    uint64 `json:"seq"`
	}
	err = json.Unmarshal(b, &header)
	if err != nil {
		return err
	}
	req.ServiceMethod = header.Method
	// req.Seq = header.Seq
	return nil
}
开发者ID:riobard,项目名称:go-snowrpc,代码行数:33,代码来源:server.go

示例5: innerReadRequestHeader

func (c *RedisServerCodec) innerReadRequestHeader(r *rpc.Request) (err error) {
	defer func() {
		if ret := recover(); ret != nil {
			err = errors.Errorf("Read Header:%s", ret)
		}
	}()

	m, err := bufioReadMessage(c.r)
	if err != nil {
		return
	}

	arr, err := m.Array()
	if err != nil {
		err = errors.Errorf("must by array type:%v", m.Type)
		return
	}

	op, _ := arr[0].Str()
	op = strings.ToLower(op)
	method, ok := methodMap[op]
	if !ok {
		err = errors.Errorf("method not supported:%s", op)
		return
	}
	r.ServiceMethod = method
	c.seq++
	r.Seq = c.seq
	c.msg = m
	return nil
}
开发者ID:icexin,项目名称:raftkv,代码行数:31,代码来源:redis.go

示例6: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
	var req protorpcpb.Request
	if err := readFrame(c.rwc, &req); err != nil {
		return err
	}
	r.ServiceMethod = req.GetMethod()
	r.Seq = req.GetSeq()
	return nil
}
开发者ID:ironzhang,项目名称:golang,代码行数:9,代码来源:server.go

示例7: writeRequest

func writeRequest(c *clientCodec) error {
	head := rpc.Request{}
	head.ServiceMethod = "TestFunc"
	head.Seq = 1

	body := testpb.Request{}
	body.Query = proto.String("ping www.tencent.com")
	return c.WriteRequest(&head, &body)
}
开发者ID:ironzhang,项目名称:golang,代码行数:9,代码来源:codec_test.go

示例8: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(request *rpc.Request) error {
	name, messageType, seq, err := c.protocol.ReadMessageBegin(c.transport)
	if err != nil {
		return err
	}
	name = CamelCase(name)
	if strings.ContainsRune(name, '.') {
		request.ServiceMethod = name
	} else {
		request.ServiceMethod = "Thrift." + name
	}
	request.Seq = uint64(seq)

	if messageType != messageTypeCall { // Currently don't support one way
		return errors.New("Exception Call message type")
	}

	return nil
}
开发者ID:lugu,项目名称:go-thrift,代码行数:19,代码来源:server.go

示例9: ReadRequestHeader

func (c *codec) ReadRequestHeader(r *rpc.Request) 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
	return nil
}
开发者ID:pascaldekloe,项目名称:colfer,代码行数:10,代码来源:rpc.go

示例10: PreWriteRequest

// PreWriteRequest adds Authorization info in requests
func (plugin *AuthorizationClientPlugin) PreWriteRequest(r *rpc.Request, body interface{}) error {
	var b bytes.Buffer
	enc := gob.NewEncoder(&b)
	plugin.AuthorizationAndServiceMethod.ServiceMethod = r.ServiceMethod
	err := enc.Encode(plugin.AuthorizationAndServiceMethod)
	if err != nil {
		return err
	}

	r.ServiceMethod = b.String()
	return nil
}
开发者ID:xiongeee,项目名称:rpcx,代码行数:13,代码来源:authorization.go

示例11: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
	err := c.readRequestHeader(c.r, &c.reqHeader)
	if err != nil {
		return err
	}

	r.Seq = c.reqHeader.Id
	if c.reqHeader.Method == nil {
		if int(c.reqHeader.MethodId) >= len(c.methods) {
			return fmt.Errorf("unexpected method-id: %d >= %d",
				c.reqHeader.MethodId, len(c.methods))
		}
		r.ServiceMethod = c.methods[c.reqHeader.MethodId]
	} else if int(c.reqHeader.MethodId) > len(c.methods) {
		return fmt.Errorf("unexpected method-id: %d > %d",
			c.reqHeader.MethodId, len(c.methods))
	} else if int(c.reqHeader.MethodId) == len(c.methods) {
		c.methods = append(c.methods, *c.reqHeader.Method)
		r.ServiceMethod = *c.reqHeader.Method
	}
	return nil
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:22,代码来源:server.go

示例12: PostReadRequestHeader

// PostReadRequestHeader extracts Authorization header from ServiceMethod field.
func (plugin *AuthorizationServerPlugin) PostReadRequestHeader(r *rpc.Request) (err error) {
	b := bytes.NewBufferString(r.ServiceMethod)
	var aAndS AuthorizationAndServiceMethod
	dec := gob.NewDecoder(b)
	err = dec.Decode(&aAndS)
	if err == nil {
		r.ServiceMethod = aAndS.ServiceMethod

		if plugin.AuthorizationFunc != nil {
			err = plugin.AuthorizationFunc(&aAndS)
		}
	}
	return
}
开发者ID:xiongeee,项目名称:rpcx,代码行数:15,代码来源:authorization.go

示例13: ReadRequestHeader

// ReadRequestHeader receives and decodes a net/rpc request header r.
func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
	// This is almost identical to ReadResponseHeader(), above.
	var err error
	var hdr ProtoRPCRequestHeader
	if err = c.m.ReadMessage(&hdr); err != nil {
		// Don't log an error here, since this is where normal EOF
		// happens over net/rpc channels, e.g., if a client finishes and
		// disconnects.
		return err
	}
	r.Seq = *hdr.Seq
	r.ServiceMethod = *hdr.Op
	return nil
}
开发者ID:William-J-Earl,项目名称:cloudproxy,代码行数:15,代码来源:protorpc.go

示例14: ReadRequestHeader

// ReadRequestHeader reads the header protobuf (which is prefixed by a uvarint
// indicating its size) from the connection, decodes it, and stores the fields
// in the given request.
func (s *ServerCodec) ReadRequestHeader(req *rpc.Request) error {
	var header wire.Header
	if err := ReadProto(s.r, &header); err != nil {
		return err
	}
	if header.Method == nil {
		return fmt.Errorf("header missing method: %s", header)
	}
	if header.Seq == nil {
		return fmt.Errorf("header missing seq: %s", header)
	}
	req.ServiceMethod = *header.Method
	req.Seq = *header.Seq
	return nil
}
开发者ID:pguelpa,项目名称:go-rpcgen,代码行数:18,代码来源:codec.go

示例15: ReadRequestHeader

func (c *serverCodec) ReadRequestHeader(r *rpc.Request) error {
	msg := <-c.msgs
	c.req.reset()
	if err := json.Unmarshal(msg.Body, &c.req); err != nil {
		return err
	}
	r.ServiceMethod = c.req.Method
	c.Lock()
	c.seq++
	c.pending[c.seq] = prop{msg.CorrelationId, msg.ReplyTo}
	r.Seq = c.seq
	c.Unlock()

	return nil
}
开发者ID:pakudayo,项目名称:mqrpc,代码行数:15,代码来源:server.go


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