本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}