本文整理汇总了Golang中github.com/juju/juju/rpc/rpcreflect.ObjTypeOf函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjTypeOf函数的具体用法?Golang ObjTypeOf怎么用?Golang ObjTypeOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjTypeOf函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTypeOf
func (*reflectSuite) TestTypeOf(c *gc.C) {
rtype := rpcreflect.TypeOf(reflect.TypeOf(&Root{}))
c.Assert(rtype.DiscardedMethods(), gc.DeepEquals, []string{
"Discard1",
"Discard2",
"Discard3",
})
expect := map[string]reflect.Type{
"CallbackMethods": reflect.TypeOf(&CallbackMethods{}),
"ChangeAPIMethods": reflect.TypeOf(&ChangeAPIMethods{}),
"DelayedMethods": reflect.TypeOf(&DelayedMethods{}),
"ErrorMethods": reflect.TypeOf(&ErrorMethods{}),
"InterfaceMethods": reflect.TypeOf((*InterfaceMethods)(nil)).Elem(),
"SimpleMethods": reflect.TypeOf(&SimpleMethods{}),
}
c.Assert(rtype.MethodNames(), gc.HasLen, len(expect))
for name, expectGoType := range expect {
m, err := rtype.Method(name)
c.Assert(err, jc.ErrorIsNil)
c.Assert(m, gc.NotNil)
c.Assert(m.Call, gc.NotNil)
c.Assert(m.ObjType, gc.Equals, rpcreflect.ObjTypeOf(expectGoType))
c.Assert(m.ObjType.GoType(), gc.Equals, expectGoType)
}
m, err := rtype.Method("not found")
c.Assert(err, gc.Equals, rpcreflect.ErrMethodNotFound)
c.Assert(m, gc.DeepEquals, rpcreflect.RootMethod{})
}
示例2: lookupMethod
func (r *apiRoot) lookupMethod(rootName string, version int, methodName string) (reflect.Type, rpcreflect.ObjMethod, error) {
noMethod := rpcreflect.ObjMethod{}
goType, err := common.Facades.GetType(rootName, version)
if err != nil {
if errors.IsNotFound(err) {
return nil, noMethod, &rpcreflect.CallNotImplementedError{
RootMethod: rootName,
Version: version,
}
}
return nil, noMethod, err
}
rpcType := rpcreflect.ObjTypeOf(goType)
objMethod, err := rpcType.Method(methodName)
if err != nil {
if err == rpcreflect.ErrMethodNotFound {
return nil, noMethod, &rpcreflect.CallNotImplementedError{
RootMethod: rootName,
Version: version,
Method: methodName,
}
}
return nil, noMethod, err
}
return goType, objMethod, nil
}
示例3: FindMethod
func (cc *CustomMethodFinder) FindMethod(
rootMethodName string, version int, objMethodName string,
) (
rpcreflect.MethodCaller, error,
) {
logger.Debugf("got to FindMethod: %q %d %q", rootMethodName, version, objMethodName)
if rootMethodName != "MultiVersion" {
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootMethodName,
}
}
var goType reflect.Type
var wrap wrapper
switch version {
case 0:
goType = reflect.TypeOf((*VariableMethods1)(nil))
wrap = func(sm *SimpleMethods) reflect.Value {
return reflect.ValueOf(&VariableMethods1{sm})
}
case 1:
goType = reflect.TypeOf((*VariableMethods2)(nil))
wrap = func(sm *SimpleMethods) reflect.Value {
return reflect.ValueOf(&VariableMethods2{sm})
}
case 2:
goType = reflect.TypeOf((*RestrictedMethods)(nil))
wrap = func(sm *SimpleMethods) reflect.Value {
methods := &RestrictedMethods{InterfaceMethods: sm}
return reflect.ValueOf(methods)
}
default:
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootMethodName,
Version: version,
}
}
logger.Debugf("found type: %s", goType)
objType := rpcreflect.ObjTypeOf(goType)
objMethod, err := objType.Method(objMethodName)
if err != nil {
return nil, &rpcreflect.CallNotImplementedError{
RootMethod: rootMethodName,
Version: version,
Method: objMethodName,
}
}
return customMethodCaller{
objMethod: objMethod,
root: cc.root,
wrap: wrap,
expectedType: goType,
}, nil
}
示例4: TestDiscardedAPIMethods
func (*facadeRegistrySuite) TestDiscardedAPIMethods(c *gc.C) {
allFacades := common.Facades.List()
c.Assert(allFacades, gc.Not(gc.HasLen), 0)
for _, description := range allFacades {
for _, version := range description.Versions {
facadeType, err := common.Facades.GetType(description.Name, version)
c.Assert(err, gc.IsNil)
facadeObjType := rpcreflect.ObjTypeOf(facadeType)
// We must have some methods on every object returned
// by a root-level method.
c.Assert(facadeObjType.MethodNames(), gc.Not(gc.HasLen), 0)
// We don't allow any methods that don't implement
// an RPC entry point.
c.Assert(facadeObjType.DiscardedMethods(), gc.HasLen, 0)
}
}
}
示例5: TestObjTypeOf
func (*reflectSuite) TestObjTypeOf(c *gc.C) {
objType := rpcreflect.ObjTypeOf(reflect.TypeOf(&SimpleMethods{}))
c.Check(objType.DiscardedMethods(), gc.DeepEquals, []string{
"Discard1",
"Discard2",
"Discard3",
"Discard4",
})
expect := map[string]*rpcreflect.ObjMethod{
"SliceArg": {
Params: reflect.TypeOf(struct{ X []string }{}),
Result: reflect.TypeOf(stringVal{}),
},
}
for narg := 0; narg < 2; narg++ {
for nret := 0; nret < 2; nret++ {
for nerr := 0; nerr < 2; nerr++ {
retErr := nerr != 0
var m rpcreflect.ObjMethod
if narg > 0 {
m.Params = reflect.TypeOf(stringVal{})
}
if nret > 0 {
m.Result = reflect.TypeOf(stringVal{})
}
expect[callName(narg, nret, retErr)] = &m
}
}
}
c.Assert(objType.MethodNames(), gc.HasLen, len(expect))
for name, expectMethod := range expect {
m, err := objType.Method(name)
c.Check(err, jc.ErrorIsNil)
c.Assert(m, gc.NotNil)
c.Check(m.Call, gc.NotNil)
c.Check(m.Params, gc.Equals, expectMethod.Params)
c.Check(m.Result, gc.Equals, expectMethod.Result)
}
m, err := objType.Method("not found")
c.Check(err, gc.Equals, rpcreflect.ErrMethodNotFound)
c.Check(m, gc.DeepEquals, rpcreflect.ObjMethod{})
}
示例6: generateInfo
func generateInfo() (*apidoc.Info, error) {
serverPkg := "github.com/juju/juju/apiserver"
cfg := loader.Config{
TypeCheckFuncBodies: func(string) bool {
return true
},
ImportPkgs: map[string]bool{
serverPkg: false, // false means don't load tests.
},
ParserMode: parser.ParseComments,
}
prog, err := cfg.Load()
if err != nil {
return nil, errgo.Notef(err, "cannot load %q", serverPkg)
}
info := jsontypes.NewInfo()
ds := common.Facades.ListDetails()
ds = append(ds, apiserver.AdminFacadeDetails()...)
for _, d := range ds {
t := rpcreflect.ObjTypeOf(d.Type)
for _, name := range t.MethodNames() {
m, _ := t.Method(name)
if m.Params != nil {
info.TypeInfo(m.Params)
}
if m.Result != nil {
info.TypeInfo(m.Result)
}
}
}
apiInfo := &apidoc.Info{
TypeInfo: info,
}
for _, d := range ds {
f := apidoc.FacadeInfo{
Name: d.Name,
Version: d.Version,
}
pt, err := progType(prog, d.Type)
if err != nil {
return nil, errgo.Notef(err, "cannot get prog type for %v", d.Type)
}
tdoc, err := typeDocComment(prog, pt)
if err != nil {
return nil, errgo.Notef(err, "cannot get doc comment for %v: %v", d.Type)
}
f.Doc = tdoc
t := rpcreflect.ObjTypeOf(d.Type)
for _, name := range t.MethodNames() {
m, _ := t.Method(name)
fm := apidoc.Method{
Name: name,
}
if m.Params != nil {
fm.Param = info.Ref(m.Params)
}
if m.Result != nil {
fm.Result = info.Ref(m.Result)
}
mdoc, err := methodDocComment(prog, pt, name)
if err != nil {
return nil, errgo.Notef(err, "cannot get doc comment for %v.%v: %v", d.Type, name)
}
fm.Doc = mdoc
f.Methods = append(f.Methods, fm)
}
apiInfo.Facades = append(apiInfo.Facades, f)
}
return apiInfo, nil
}