1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
auto_configure_processor.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
package processor
import (
"gitee.com/kristas/booting-go/framework/common/util/reflectx"
"gitee.com/kristas/booting-go/framework/core/bean"
"gitee.com/kristas/booting-go/framework/core/component"
"gitee.com/kristas/booting-go/framework/core/configure"
"gitee.com/kristas/booting-go/framework/logging"
"reflect"
)
type AutoConfigureProcessor struct {
Log logging.Logger `bean:"log"`
}
func (r *AutoConfigureProcessor) Filter(bean bean.Bean) bool {
return true
}
func (r *AutoConfigureProcessor) Do(b bean.Bean) {
reflectx.WalkStructField(b, func(field reflect.StructField, value reflect.Value) {
if t, ok := field.Tag.Lookup("configure"); ok && t == "auto" {
if field.Type.Implements(reflect.TypeOf(new(component.Configuration)).Elem()) {
conf := reflect.New(field.Type.Elem())
configure.InjectConfiguration(conf.Interface().(component.Configuration))
value.Set(conf)
} else {
r.Log.Errorf("%s is not implement configuration", field.Type)
}
}
//if field.Type.Implements(reflect.TypeOf(new(announce.Configuration)).Elem()) {
// conf := reflect.New(field.Type.Elem())
// configure.InjectConfiguration(conf.Interface().(announce.Configuration))
// value.Set(conf)
//}
}, true)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.2.9

搜索帮助