From fa9284537fb90647bbc36c5ed3f7c255d538b172 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Wed, 3 May 2023 17:13:19 +0800 Subject: [PATCH] fix: vto type error --- README.md | 4 +++- README_zh.md | 4 +++- container/pool/list.go | 2 +- tools/vto/votodo.go | 16 ++++++++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dc48f37..0baf0f1 100644 --- a/README.md +++ b/README.md @@ -408,7 +408,9 @@ func main() { ## container -Containerized components +> Pool, but you can customize the creation function and replace the initialization function. +> pool pooling object, through the configuration can set the maximum number of connections and the number of waiting connections, synchronous asynchronous acquisition of connections, and connection life cycle management, you can customize the creation function, and replace the initialization function +> codel implement codel algorithm, can be used to limit the flow, and fuse ### group diff --git a/README_zh.md b/README_zh.md index a5e5733..0bbb1f6 100644 --- a/README_zh.md +++ b/README_zh.md @@ -406,7 +406,9 @@ func main() { ## container -容器化组件 +> group 适用于生命周期较长对象的懒加载,类似于 sync.Pool,但是可以自定义创建函数,以及更换初始化函数 +> pool 池化对象,通过配置可以设置最大连接数以及等待连接数,同步异步获取连接,以及连接的生命周期管理,可以自定义创建函数,以及更换初始化函数 +> codel 实现codel算法,可以用于限流,以及熔断 ### group diff --git a/container/pool/list.go b/container/pool/list.go index 62bb261..fd9c556 100644 --- a/container/pool/list.go +++ b/container/pool/list.go @@ -231,7 +231,7 @@ func (l *List) Put(ctx context.Context, s IShutdown, forceClose bool) error { return s.Shutdown() } -// IShutdown 关闭 +// Shutdown 关闭 func (l *List) Shutdown() error { l.mu.Lock() if atomic.SwapUint32(&l.closed, 1) == 1 { diff --git a/tools/vto/votodo.go b/tools/vto/votodo.go index affff80..bc5905d 100644 --- a/tools/vto/votodo.go +++ b/tools/vto/votodo.go @@ -58,7 +58,7 @@ func VoToDo(dst interface{}, src interface{}) error { continue } - if d.Type() != s.Type() && d.Kind() == reflect.Struct { + if d.Kind() != s.Kind() && d.Kind() == reflect.Struct { err := VoToDo(d.Addr().Interface(), s.Addr().Interface()) if err != nil { return err @@ -67,7 +67,11 @@ func VoToDo(dst interface{}, src interface{}) error { } if !s.IsZero() { - d.Set(s) + if d.Type() == s.Type() { + d.Set(s) + } else { + d.Set(reflect.ValueOf(s.Interface()).Convert(d.Type())) + } } // 如果源位置的内容为空,并且默认值不为0 @@ -131,7 +135,7 @@ func VoToDoPlus(dst interface{}, src interface{}, model ModelParameters) error { continue } - if d.Type() != s.Type() && d.Kind() == reflect.Struct { + if d.Kind() != s.Kind() && d.Kind() == reflect.Struct { err := VoToDoPlus(d.Addr().Interface(), s.Addr().Interface(), model) if err != nil { return err @@ -140,7 +144,11 @@ func VoToDoPlus(dst interface{}, src interface{}, model ModelParameters) error { } if !s.IsZero() { - d.Set(s) + if d.Type() == s.Type() { + d.Set(s) + } else { + d.Set(reflect.ValueOf(s.Interface()).Convert(d.Type())) + } } } }