mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
expose package internal/structs as os/gstructs; add package gtag for custom tag storage feature
This commit is contained in:
@ -19,8 +19,8 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/structs"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/os/gstructs"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@ -96,7 +96,7 @@ func getTableNameFromOrmTag(object interface{}) string {
|
||||
}
|
||||
// Use the struct name of snake case.
|
||||
if tableName == "" {
|
||||
if t, err := structs.StructType(object); err != nil {
|
||||
if t, err := gstructs.StructType(object); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
tableName = gstr.CaseSnakeFirstUpper(
|
||||
@ -306,9 +306,9 @@ func doQuoteString(s, charLeft, charRight string) string {
|
||||
func getFieldsFromStructOrMap(structOrMap interface{}) (fields []string) {
|
||||
fields = []string{}
|
||||
if utils.IsStruct(structOrMap) {
|
||||
structFields, _ := structs.Fields(structs.FieldsInput{
|
||||
structFields, _ := gstructs.Fields(gstructs.FieldsInput{
|
||||
Pointer: structOrMap,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
for _, structField := range structFields {
|
||||
if tag := structField.Tag(OrmTagForStruct); tag != "" && gregex.IsMatchString(regularFieldNameRegPattern, tag) {
|
||||
|
||||
@ -13,8 +13,8 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/structs"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/os/gstructs"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
@ -65,10 +65,10 @@ func (m *Model) doWithScanStruct(pointer interface{}) error {
|
||||
err error
|
||||
allowedTypeStrArray = make([]string, 0)
|
||||
)
|
||||
currentStructFieldMap, err := structs.FieldMap(structs.FieldMapInput{
|
||||
currentStructFieldMap, err := gstructs.FieldMap(gstructs.FieldMapInput{
|
||||
Pointer: pointer,
|
||||
PriorityTagArray: nil,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -77,7 +77,7 @@ func (m *Model) doWithScanStruct(pointer interface{}) error {
|
||||
if !m.withAll {
|
||||
for _, field := range currentStructFieldMap {
|
||||
for _, withItem := range m.withArray {
|
||||
withItemReflectValueType, err := structs.StructType(withItem)
|
||||
withItemReflectValueType, err := gstructs.StructType(withItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -137,7 +137,7 @@ func (m *Model) doWithScanStruct(pointer interface{}) error {
|
||||
}
|
||||
|
||||
// It automatically retrieves struct field names from current attribute struct/slice.
|
||||
if structType, err := structs.StructType(field.Value); err != nil {
|
||||
if structType, err := gstructs.StructType(field.Value); err != nil {
|
||||
return err
|
||||
} else {
|
||||
fieldKeys = structType.FieldKeys()
|
||||
@ -176,10 +176,10 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
|
||||
err error
|
||||
allowedTypeStrArray = make([]string, 0)
|
||||
)
|
||||
currentStructFieldMap, err := structs.FieldMap(structs.FieldMapInput{
|
||||
currentStructFieldMap, err := gstructs.FieldMap(gstructs.FieldMapInput{
|
||||
Pointer: pointer,
|
||||
PriorityTagArray: nil,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -188,7 +188,7 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
|
||||
if !m.withAll {
|
||||
for _, field := range currentStructFieldMap {
|
||||
for _, withItem := range m.withArray {
|
||||
withItemReflectValueType, err := structs.StructType(withItem)
|
||||
withItemReflectValueType, err := gstructs.StructType(withItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -244,7 +244,7 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
|
||||
}
|
||||
|
||||
// It automatically retrieves struct field names from current attribute struct/slice.
|
||||
if structType, err := structs.StructType(field.Value); err != nil {
|
||||
if structType, err := gstructs.StructType(field.Value); err != nil {
|
||||
return err
|
||||
} else {
|
||||
fieldKeys = structType.FieldKeys()
|
||||
@ -281,7 +281,7 @@ type parseWithTagInFieldStructOutput struct {
|
||||
Order string
|
||||
}
|
||||
|
||||
func (m *Model) parseWithTagInFieldStruct(field structs.Field) (output parseWithTagInFieldStructOutput) {
|
||||
func (m *Model) parseWithTagInFieldStruct(field gstructs.Field) (output parseWithTagInFieldStructOutput) {
|
||||
var (
|
||||
match []string
|
||||
ormTag = field.Tag(OrmTagForStruct)
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/structs"
|
||||
"github.com/gogf/gf/v2/os/gstructs"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
@ -356,9 +356,9 @@ func doScanList(in doScanListInput) (err error) {
|
||||
if in.RelationFields != "" && !relationBindToFieldNameChecked {
|
||||
relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName)
|
||||
if !relationFromAttrField.IsValid() {
|
||||
filedMap, _ := structs.FieldMap(structs.FieldMapInput{
|
||||
filedMap, _ := gstructs.FieldMap(gstructs.FieldMapInput{
|
||||
Pointer: relationFromAttrValue,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
if key, _ := gutil.MapPossibleItemByKey(gconv.Map(filedMap), relationBindToFieldName); key == "" {
|
||||
return gerror.NewCodef(
|
||||
|
||||
Reference in New Issue
Block a user