Merge pull request 'by Robin at 20240326; fix high concurrency problem' (#208) from feat-IRONFANS-ALTER-Robin into main
Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/208
This commit is contained in:
commit
43e2d412fa
|
@ -10,7 +10,7 @@ import (
|
||||||
//标签格式为string|int|int
|
//标签格式为string|int|int
|
||||||
|
|
||||||
type CryptoTagInterceptor struct {
|
type CryptoTagInterceptor struct {
|
||||||
cryptoEleQueue *list.List //队列
|
//cryptoEleQueue *list.List //队列
|
||||||
printableCryptoFun printableCryptoFunc //将拦截到的[]byte进行可打印加密/解密的方法
|
printableCryptoFun printableCryptoFunc //将拦截到的[]byte进行可打印加密/解密的方法
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func newCryptoTagInterceptor() *CryptoTagInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (interceptor *CryptoTagInterceptor) Init() {
|
func (interceptor *CryptoTagInterceptor) Init() {
|
||||||
interceptor.cryptoEleQueue = list.New()
|
//interceptor.cryptoEleQueue = list.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (interceptor *CryptoTagInterceptor) LoadPrintableCryptoFunc(printableCryptoFun printableCryptoFunc) {
|
func (interceptor *CryptoTagInterceptor) LoadPrintableCryptoFunc(printableCryptoFun printableCryptoFunc) {
|
||||||
|
@ -31,15 +31,17 @@ func (interceptor *CryptoTagInterceptor) LoadPrintableCryptoFunc(printableCrypto
|
||||||
// 拦截方法
|
// 拦截方法
|
||||||
func (interceptor *CryptoTagInterceptor) Intercept(p any, tags ...string) (err error) {
|
func (interceptor *CryptoTagInterceptor) Intercept(p any, tags ...string) (err error) {
|
||||||
|
|
||||||
|
cryptoEleQueue := list.New()
|
||||||
|
|
||||||
//解析当前类的标签
|
//解析当前类的标签
|
||||||
if err = interceptor.parse(p, tags...); err != nil {
|
if err = interceptor.parse(p, cryptoEleQueue, tags...); err != nil {
|
||||||
logger.Error("parse failed:%v", err)
|
logger.Error("parse failed:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//开始遍历标签
|
//开始遍历标签
|
||||||
for interceptor.cryptoEleQueue.Len() != 0 {
|
for cryptoEleQueue.Len() != 0 {
|
||||||
ele := interceptor.cryptoEleQueue.Remove(interceptor.cryptoEleQueue.Front())
|
ele := cryptoEleQueue.Remove(cryptoEleQueue.Front())
|
||||||
if ele == nil {
|
if ele == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -50,13 +52,13 @@ func (interceptor *CryptoTagInterceptor) Intercept(p any, tags ...string) (err e
|
||||||
}
|
}
|
||||||
|
|
||||||
if cryptoElement.eleType == StructPtr { // *struct
|
if cryptoElement.eleType == StructPtr { // *struct
|
||||||
if err = interceptor.parse(cryptoElement.eleValue.Interface(), tags...); err != nil {
|
if err = interceptor.parse(cryptoElement.eleValue.Interface(), cryptoEleQueue, tags...); err != nil {
|
||||||
logger.Error("parse failed:%v", err)
|
logger.Error("parse failed:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if cryptoElement.eleType == StructPtrSlice { // []*struct
|
} else if cryptoElement.eleType == StructPtrSlice { // []*struct
|
||||||
for i := 0; i < cryptoElement.eleValue.Len(); i++ {
|
for i := 0; i < cryptoElement.eleValue.Len(); i++ {
|
||||||
err = interceptor.parse(cryptoElement.eleValue.Index(i).Interface(), tags...)
|
err = interceptor.parse(cryptoElement.eleValue.Index(i).Interface(), cryptoEleQueue, tags...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("parse failed:%v", err)
|
logger.Error("parse failed:%v", err)
|
||||||
return
|
return
|
||||||
|
@ -71,7 +73,7 @@ func (interceptor *CryptoTagInterceptor) Intercept(p any, tags ...string) (err e
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析标签并写入队列
|
// 解析标签并写入队列
|
||||||
func (interceptor *CryptoTagInterceptor) parse(p any, tags ...string) error {
|
func (interceptor *CryptoTagInterceptor) parse(p any, cryptoEleQueue *list.List, tags ...string) error {
|
||||||
|
|
||||||
pType := reflect.TypeOf(p).Elem() //获取到具体的struct名称
|
pType := reflect.TypeOf(p).Elem() //获取到具体的struct名称
|
||||||
pValue := reflect.ValueOf(p).Elem() //获取到struct的值类型
|
pValue := reflect.ValueOf(p).Elem() //获取到struct的值类型
|
||||||
|
@ -118,15 +120,15 @@ func (interceptor *CryptoTagInterceptor) parse(p any, tags ...string) error {
|
||||||
|
|
||||||
//4.拦截*struct,入队
|
//4.拦截*struct,入队
|
||||||
} else if util.IsTypeStructPtr(fieldType) && field.Tag.Get(tag) == "true" && !pValue.Field(i).IsNil() {
|
} else if util.IsTypeStructPtr(fieldType) && field.Tag.Get(tag) == "true" && !pValue.Field(i).IsNil() {
|
||||||
interceptor.cryptoEleQueue.PushBack(newCryptoElement(StructPtr, pValue.Field(i)))
|
cryptoEleQueue.PushBack(newCryptoElement(StructPtr, pValue.Field(i)))
|
||||||
|
|
||||||
//5.拦截[]*Struct,入队
|
//5.拦截[]*Struct,入队
|
||||||
} else if util.IsTypeStructPtrSlice(fieldType) && field.Tag.Get(tag) == "true" && !pValue.Field(i).IsNil() {
|
} else if util.IsTypeStructPtrSlice(fieldType) && field.Tag.Get(tag) == "true" && !pValue.Field(i).IsNil() {
|
||||||
interceptor.cryptoEleQueue.PushBack(newCryptoElement(StructPtrSlice, pValue.Field(i)))
|
cryptoEleQueue.PushBack(newCryptoElement(StructPtrSlice, pValue.Field(i)))
|
||||||
|
|
||||||
//6.拦截struct,入队
|
//6.拦截struct,入队
|
||||||
} else if util.IsTypeStruct(fieldType) && field.Tag.Get(tag) != "" {
|
} else if util.IsTypeStruct(fieldType) && field.Tag.Get(tag) != "" {
|
||||||
interceptor.cryptoEleQueue.PushBack(newCryptoElement(StructPtr, pValue.Field(i).Addr()))
|
cryptoEleQueue.PushBack(newCryptoElement(StructPtr, pValue.Field(i).Addr()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue