You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package wrapper
import (
"git.noahlan.cn/noahlan/ntool/nmap"
"git.noahlan.cn/noahlan/ntool/nreflect"
"reflect"
"time"
)
// StrCommonWrapper 将普通字段转换为string
// 支持如下类型
// reflect.Invalid -> ""
// reflect.Bool -> "true", "false"
// reflect.String -> "str"
// reflect.Float32,reflect.Float64 -> "x.x"
// reflect.IntX -> "1"
// reflect.UintX -> "1"
// 非以上类型的, 使用fmt.Sprint进行格式化
type StrCommonWrapper struct {
BaseTypeWrapper
}
func NewStrCommonWrapper ( ) TypeWrapper {
return & StrCommonWrapper { }
}
func ( * StrCommonWrapper ) Supported ( value reflect . Value ) bool {
// 不对time类型做处理
if _ , ok := value . Interface ( ) . ( time . Time ) ; ok {
return false
}
return true
}
func ( * StrCommonWrapper ) Wrap ( valueElem reflect . Value , index int , tagMap nmap . SMap ) reflect . Value {
return reflect . ValueOf ( nreflect . String ( valueElem ) )
}
func ( t * StrCommonWrapper ) Set ( fieldElem reflect . Value , value any , tagMap nmap . SMap ) {
// Set是仅针对struct的情况
}