上传json序列化保护

This commit is contained in:
liwei1dao 2022-10-13 11:12:40 +08:00
parent d60181b948
commit 2f2894af6a
2 changed files with 17 additions and 2 deletions

View File

@ -3,6 +3,8 @@ package factory
import ( import (
"errors" "errors"
"fmt" "fmt"
"go_dreamfactory/lego/utils/codec/codecore"
"go_dreamfactory/lego/utils/codec/utils"
"io" "io"
"reflect" "reflect"
"sort" "sort"
@ -10,8 +12,6 @@ import (
"unicode" "unicode"
"unsafe" "unsafe"
"go_dreamfactory/lego/utils/codec/codecore"
"github.com/modern-go/reflect2" "github.com/modern-go/reflect2"
) )
@ -108,6 +108,9 @@ func describeStruct(ctx *codecore.Ctx, typ reflect2.Type) *StructDescriptor {
bindings := []*Binding{} bindings := []*Binding{}
for i := 0; i < structType.NumField(); i++ { for i := 0; i < structType.NumField(); i++ {
field := structType.Field(i) field := structType.Field(i)
if !utils.IsExported(field.Name()) { //内部字段不处理
continue
}
tag, hastag := field.Tag().Lookup(ctx.Config.TagKey) tag, hastag := field.Tag().Lookup(ctx.Config.TagKey)
if ctx.Config.OnlyTaggedField && !hastag && !field.Anonymous() { if ctx.Config.OnlyTaggedField && !hastag && !field.Anonymous() {
continue continue

View File

@ -0,0 +1,12 @@
package utils
import (
"unicode"
"unicode/utf8"
)
///是否是内部字段
func IsExported(name string) bool {
rune, _ := utf8.DecodeRuneInString(name)
return unicode.IsUpper(rune)
}