zz_generated.ioc.go文件中包含哪些自动生成的代码?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
zz_generated.ioc.go文件中包含以下自动生成的代码:
结构注册代码:将结构的生命周期以结构描述符的形式注册到框架上。
func init() { 
singleton.RegisterStructDescriptor(&autowire.StructDescriptor{ 
Factory: func() interface{} { 
return &Impl1{} 
}, 
}) 
}
结构专属接口:命名为$(结构名)IOCInterface,用于面向接口编程。
type Impl1IOCInterface interface { 
Hello(req string) string 
}
结构代理层存根:为所有结构提供代理层,扩展运维能力。
``` type impl1 struct {
 Hello func(req string) string
 } 
 func (i *impl1) Hello(req string) string { return i.Hello(req)
}
结构获取API:提供获取结构指针和包装了代理层的专属接口的函数。
// 获取结构指针 
func GetImpl1() (*Impl1, error) { 
i, err := singleton.GetImpl(util.GetSDIDByStructPtr(new(Impl1)), nil) 
if err != nil { 
return nil, err 
} 
impl := i.(*Impl1) 
return impl, nil 
} 
// 获取包装了代理层的专属接口 
func GetImpl1IOCInterface() (Impl1IOCInterface, error) { 
i, err := singleton.GetImplWithProxy(util.GetSDIDByStructPtr(new(Impl1)), nil) 
if err != nil { 
return nil, err 
} 
impl := i.(Impl1IOCInterface) 
return impl, nil 
}
```