本文整理汇总了Golang中github.com/juju/juju/rpc/rpcreflect.ValueOf函数的典型用法代码示例。如果您正苦于以下问题:Golang ValueOf函数的具体用法?Golang ValueOf怎么用?Golang ValueOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValueOf函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestValueOf
func (*reflectSuite) TestValueOf(c *gc.C) {
v := rpcreflect.ValueOf(reflect.ValueOf(nil))
c.Check(v.IsValid(), jc.IsFalse)
c.Check(func() { v.FindMethod("foo", 0, "bar") }, gc.PanicMatches, "FindMethod called on invalid Value")
root := &Root{}
v = rpcreflect.ValueOf(reflect.ValueOf(root))
c.Check(v.IsValid(), jc.IsTrue)
c.Check(v.GoValue().Interface(), gc.Equals, root)
}
开发者ID:howbazaar,项目名称:juju,代码行数:10,代码来源:reflect_test.go
示例2: TestFindMethod
func (*reflectSuite) TestFindMethod(c *gc.C) {
// FindMethod is actually extensively tested because it's
// used in the implementation of the rpc server,
// so just a simple sanity check test here.
root := &Root{
simple: make(map[string]*SimpleMethods),
}
root.simple["a99"] = &SimpleMethods{root: root, id: "a99"}
v := rpcreflect.ValueOf(reflect.ValueOf(root))
m, err := v.FindMethod("foo", 0, "bar")
c.Assert(err, gc.ErrorMatches, `unknown object type "foo"`)
c.Assert(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
c.Assert(m, gc.IsNil)
m, err = v.FindMethod("SimpleMethods", 0, "bar")
c.Assert(err, gc.ErrorMatches, "no such request - method SimpleMethods.bar is not implemented")
c.Assert(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
c.Assert(m, gc.IsNil)
m, err = v.FindMethod("SimpleMethods", 0, "Call1r1e")
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.ParamsType(), gc.Equals, reflect.TypeOf(stringVal{}))
c.Assert(m.ResultType(), gc.Equals, reflect.TypeOf(stringVal{}))
ret, err := m.Call("a99", reflect.ValueOf(stringVal{"foo"}))
c.Assert(err, jc.ErrorIsNil)
c.Assert(ret.Interface(), gc.Equals, stringVal{"Call1r1e ret"})
}
开发者ID:howbazaar,项目名称:juju,代码行数:29,代码来源:reflect_test.go
示例3: Serve
// Serve serves RPC requests on the connection by invoking methods on
// root. Note that it does not start the connection running,
// though it may be called once the connection is already started.
//
// The server executes each client request by calling a method on root
// to obtain an object to act on; then it invokes an method on that
// object with the request parameters, possibly returning some result.
//
// Methods on the root value are of the form:
//
// M(id string) (O, error)
//
// where M is an exported name, conventionally naming the object type,
// id is some identifier for the object and O is the type of the
// returned object.
//
// Methods defined on O may defined in one of the following forms, where
// T and R must be struct types.
//
// Method()
// Method() R
// Method() (R, error)
// Method() error
// Method(T)
// Method(T) R
// Method(T) (R, error)
// Method(T) error
//
// If transformErrors is non-nil, it will be called on all returned
// non-nil errors, for example to transform the errors into ServerErrors
// with specified codes. There will be a panic if transformErrors
// returns nil.
//
// Serve may be called at any time on a connection to change the
// set of methods being served by the connection. This will have
// no effect on calls that are currently being services.
// If root is nil, the connection will serve no methods.
func (conn *Conn) Serve(root interface{}, transformErrors func(error) error) {
rootValue := rpcreflect.ValueOf(reflect.ValueOf(root))
if rootValue.IsValid() {
conn.serve(rootValue, transformErrors)
} else {
conn.serve(nil, transformErrors)
}
}
开发者ID:bac,项目名称:juju,代码行数:45,代码来源:server.go
示例4: TestErrorRootViaRPC
func (s *errRootSuite) TestErrorRootViaRPC(c *gc.C) {
origErr := fmt.Errorf("my custom error")
errRoot := apiserver.NewErrRoot(origErr)
val := rpcreflect.ValueOf(reflect.ValueOf(errRoot))
caller, err := val.FindMethod("Admin", 0, "Login")
c.Assert(err, jc.ErrorIsNil)
resp, err := caller.Call("", reflect.Value{})
c.Check(err, gc.Equals, origErr)
c.Check(resp.IsValid(), jc.IsFalse)
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:root_test.go
示例5: Serve
// Serve serves RPC requests on the connection by invoking methods on
// root. Note that it does not start the connection running,
// though it may be called once the connection is already started.
//
// The server executes each client request by calling a method on root
// to obtain an object to act on; then it invokes an method on that
// object with the request parameters, possibly returning some result.
//
// Methods on the root value are of the form:
//
// M(id string) (O, error)
//
// where M is an exported name, conventionally naming the object type,
// id is some identifier for the object and O is the type of the
// returned object.
//
// Methods defined on O may defined in one of the following forms, where
// T and R must be struct types.
//
// Method()
// Method() R
// Method() (R, error)
// Method() error
// Method(T)
// Method(T) R
// Method(T) (R, error)
// Method(T) error
//
// If transformErrors is non-nil, it will be called on all returned
// non-nil errors, for example to transform the errors into ServerErrors
// with specified codes. There will be a panic if transformErrors
// returns nil.
//
// Serve may be called at any time on a connection to change the
// set of methods being served by the connection. This will have
// no effect on calls that are currently being services.
// If root is nil, the connection will serve no methods.
func (conn *Conn) Serve(root interface{}, transformErrors func(error) error) {
rootValue := rpcreflect.ValueOf(reflect.ValueOf(root))
if rootValue.IsValid() && transformErrors == nil {
transformErrors = func(err error) error { return err }
}
conn.mutex.Lock()
defer conn.mutex.Unlock()
conn.rootValue = rootValue
conn.transformErrors = transformErrors
}
开发者ID:rogpeppe,项目名称:juju,代码行数:47,代码来源:server.go
示例6: serveConn
func (srv *Server) serveConn(wsConn *websocket.Conn, modelUUID string) {
codec := jsoncodec.NewWebsocket(wsConn)
conn := rpc.NewConn(codec, &fakeobserver.Instance{})
root := allVersions{
rpcreflect.ValueOf(reflect.ValueOf(srv.newRoot(modelUUID))),
}
conn.ServeRoot(root, nil)
conn.Start()
<-conn.Dead()
conn.Close()
}
开发者ID:bac,项目名称:juju,代码行数:12,代码来源:fakeapi.go
示例7: FindMethod
func (r *anonRoot) FindMethod(rootName string, version int, methodName string) (rpcreflect.MethodCaller, error) {
if rootName != "Admin" {
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootName,
Version: version,
}
}
if api, ok := r.adminAPIs[version]; ok {
return rpcreflect.ValueOf(reflect.ValueOf(api)).FindMethod(rootName, 0, methodName)
}
return nil, &rpc.RequestError{
Code: params.CodeNotSupported,
Message: "this version of Juju does not support login from old clients",
}
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:root.go
示例8: TestFindMethodRefusesVersionsNot0
func (*reflectSuite) TestFindMethodRefusesVersionsNot0(c *gc.C) {
root := &Root{
simple: make(map[string]*SimpleMethods),
}
root.simple["a99"] = &SimpleMethods{root: root, id: "a99"}
v := rpcreflect.ValueOf(reflect.ValueOf(root))
m, err := v.FindMethod("SimpleMethods", 0, "Call1r1e")
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.ParamsType(), gc.Equals, reflect.TypeOf(stringVal{}))
c.Assert(m.ResultType(), gc.Equals, reflect.TypeOf(stringVal{}))
m, err = v.FindMethod("SimpleMethods", 1, "Call1r1e")
c.Assert(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil))
c.Assert(err, gc.ErrorMatches, `unknown version \(1\) of interface "SimpleMethods"`)
}
开发者ID:howbazaar,项目名称:juju,代码行数:16,代码来源:reflect_test.go
示例9: FindMethod
func (r *anonRoot) FindMethod(rootName string, version int, methodName string) (rpcreflect.MethodCaller, error) {
if rootName != "Admin" {
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootName,
Version: version,
}
}
if api, ok := r.adminApis[version]; ok {
return rpcreflect.ValueOf(reflect.ValueOf(api)).FindMethod(rootName, 0, methodName)
}
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootName,
Method: methodName,
Version: version,
}
}
开发者ID:pmatulis,项目名称:juju,代码行数:16,代码来源:root.go
注:本文中的github.com/juju/juju/rpc/rpcreflect.ValueOf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论