本文整理匯總了Golang中github.com/juju/juju/rpc.Header.IsRequest方法的典型用法代碼示例。如果您正苦於以下問題:Golang Header.IsRequest方法的具體用法?Golang Header.IsRequest怎麽用?Golang Header.IsRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/rpc.Header
的用法示例。
在下文中一共展示了Header.IsRequest方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteMessage
func (c *testCodec) WriteMessage(hdr *rpc.Header, x interface{}) error {
if reflect.ValueOf(x).Kind() != reflect.Struct {
panic(fmt.Errorf("WriteRequest bad param; want struct got %T (%#v)", x, x))
}
if c.role != roleBoth && hdr.IsRequest() != (c.role == roleClient) {
panic(fmt.Errorf("codec role %v; header wrong type %#v", c.role, hdr))
}
logger.Infof("send header: %#v; body: %#v", hdr, x)
return c.Codec.WriteMessage(hdr, x)
}
示例2: ReadHeader
func (c *testCodec) ReadHeader(hdr *rpc.Header) error {
err := c.Codec.ReadHeader(hdr)
if err != nil {
return err
}
logger.Infof("got header %#v", hdr)
if c.role != roleBoth && hdr.IsRequest() == (c.role == roleClient) {
panic(fmt.Errorf("codec role %v; read wrong type %#v", c.role, hdr))
}
return nil
}
示例3: init
// init fills out the receiving outMsg with information from the given
// header and body.
func (m *outMsg) init(hdr *rpc.Header, body interface{}) {
m.RequestId = hdr.RequestId
m.Type = hdr.Request.Type
m.Id = hdr.Request.Id
m.Request = hdr.Request.Action
m.Error = hdr.Error
m.ErrorCode = hdr.ErrorCode
if hdr.IsRequest() {
m.Params = body
} else {
m.Response = body
}
}
示例4: newOutMsgV1
// newOutMsgV1 fills out a outMsgV1 with information from the given header and
// body. This might look a lot like the v0 method, and that is because it is.
// However, since Go determins structs to be sufficiently different if the
// tags are different, we can't use the same code. Theoretically we could use
// reflect, but no.
func newOutMsgV1(hdr *rpc.Header, body interface{}) outMsgV1 {
result := outMsgV1{
RequestId: hdr.RequestId,
Type: hdr.Request.Type,
Version: hdr.Request.Version,
Id: hdr.Request.Id,
Request: hdr.Request.Action,
Error: hdr.Error,
ErrorCode: hdr.ErrorCode,
}
if hdr.IsRequest() {
result.Params = body
} else {
result.Response = body
}
return result
}
示例5: TestRead
func (*suite) TestRead(c *gc.C) {
for i, test := range readTests {
c.Logf("test %d", i)
codec := jsoncodec.New(&testConn{
readMsgs: []string{test.msg},
})
var hdr rpc.Header
err := codec.ReadHeader(&hdr)
c.Assert(err, gc.IsNil)
c.Assert(hdr, gc.DeepEquals, test.expectHdr)
c.Assert(hdr.IsRequest(), gc.Equals, test.expectHdr.IsRequest())
body := reflect.New(reflect.ValueOf(test.expectBody).Type().Elem()).Interface()
err = codec.ReadBody(body, test.expectHdr.IsRequest())
c.Assert(err, gc.IsNil)
c.Assert(body, gc.DeepEquals, test.expectBody)
err = codec.ReadHeader(&hdr)
c.Assert(err, gc.Equals, io.EOF)
}
}
示例6: TestRead
func (*suite) TestRead(c *gc.C) {
for i, test := range []struct {
msg string
expectHdr rpc.Header
expectBody interface{}
}{{
msg: `{"RequestId": 1, "Type": "foo", "Id": "id", "Request": "frob", "Params": {"X": "param"}}`,
expectHdr: rpc.Header{
RequestId: 1,
Request: rpc.Request{
Type: "foo",
Id: "id",
Action: "frob",
},
},
expectBody: &value{X: "param"},
}, {
msg: `{"RequestId": 2, "Error": "an error", "ErrorCode": "a code"}`,
expectHdr: rpc.Header{
RequestId: 2,
Error: "an error",
ErrorCode: "a code",
},
expectBody: new(map[string]interface{}),
}, {
msg: `{"RequestId": 3, "Response": {"X": "result"}}`,
expectHdr: rpc.Header{
RequestId: 3,
},
expectBody: &value{X: "result"},
}, {
msg: `{"RequestId": 4, "Type": "foo", "Version": 2, "Id": "id", "Request": "frob", "Params": {"X": "param"}}`,
expectHdr: rpc.Header{
RequestId: 4,
Request: rpc.Request{
Type: "foo",
Version: 2,
Id: "id",
Action: "frob",
},
},
expectBody: &value{X: "param"},
}, {
msg: `{"request-id": 1, "type": "foo", "id": "id", "request": "frob", "params": {"X": "param"}}`,
expectHdr: rpc.Header{
RequestId: 1,
Request: rpc.Request{
Type: "foo",
Id: "id",
Action: "frob",
},
Version: 1,
},
expectBody: &value{X: "param"},
}, {
msg: `{"request-id": 2, "error": "an error", "error-code": "a code"}`,
expectHdr: rpc.Header{
RequestId: 2,
Error: "an error",
ErrorCode: "a code",
Version: 1,
},
expectBody: new(map[string]interface{}),
}, {
msg: `{"request-id": 3, "response": {"X": "result"}}`,
expectHdr: rpc.Header{
RequestId: 3,
Version: 1,
},
expectBody: &value{X: "result"},
}, {
msg: `{"request-id": 4, "type": "foo", "version": 2, "id": "id", "request": "frob", "params": {"X": "param"}}`,
expectHdr: rpc.Header{
RequestId: 4,
Request: rpc.Request{
Type: "foo",
Version: 2,
Id: "id",
Action: "frob",
},
Version: 1,
},
expectBody: &value{X: "param"},
}} {
c.Logf("test %d", i)
codec := jsoncodec.New(&testConn{
readMsgs: []string{test.msg},
})
var hdr rpc.Header
err := codec.ReadHeader(&hdr)
c.Assert(err, jc.ErrorIsNil)
c.Assert(hdr, gc.DeepEquals, test.expectHdr)
c.Assert(hdr.IsRequest(), gc.Equals, test.expectHdr.IsRequest())
body := reflect.New(reflect.ValueOf(test.expectBody).Type().Elem()).Interface()
err = codec.ReadBody(body, test.expectHdr.IsRequest())
c.Assert(err, jc.ErrorIsNil)
c.Assert(body, gc.DeepEquals, test.expectBody)
//.........這裏部分代碼省略.........