Make receiver name of structField consistent

This commit is contained in:
David Zhang 2018-11-04 22:41:58 +08:00
parent 472c70caa4
commit 69e61e3e7f

View File

@ -21,12 +21,12 @@ var modelStructsMap sync.Map
// ModelStruct model definition // ModelStruct model definition
type ModelStruct struct { type ModelStruct struct {
PrimaryFields []*StructField PrimaryFields []*StructField
StructFields []*StructField StructFields []*StructField
ModelType reflect.Type ModelType reflect.Type
defaultTableName string defaultTableName string
l sync.Mutex l sync.Mutex
} }
// TableName returns model's table name // TableName returns model's table name
@ -91,31 +91,31 @@ func (s *StructField) TagSettingsDelete(key string) {
delete(s.TagSettings, key) delete(s.TagSettings, key)
} }
func (structField *StructField) clone() *StructField { func (s *StructField) clone() *StructField {
clone := &StructField{ clone := &StructField{
DBName: structField.DBName, DBName: s.DBName,
Name: structField.Name, Name: s.Name,
Names: structField.Names, Names: s.Names,
IsPrimaryKey: structField.IsPrimaryKey, IsPrimaryKey: s.IsPrimaryKey,
IsNormal: structField.IsNormal, IsNormal: s.IsNormal,
IsIgnored: structField.IsIgnored, IsIgnored: s.IsIgnored,
IsScanner: structField.IsScanner, IsScanner: s.IsScanner,
HasDefaultValue: structField.HasDefaultValue, HasDefaultValue: s.HasDefaultValue,
Tag: structField.Tag, Tag: s.Tag,
TagSettings: map[string]string{}, TagSettings: map[string]string{},
Struct: structField.Struct, Struct: s.Struct,
IsForeignKey: structField.IsForeignKey, IsForeignKey: s.IsForeignKey,
} }
if structField.Relationship != nil { if s.Relationship != nil {
relationship := *structField.Relationship relationship := *s.Relationship
clone.Relationship = &relationship clone.Relationship = &relationship
} }
// copy the struct field tagSettings, they should be read-locked while they are copied // copy the struct field tagSettings, they should be read-locked while they are copied
structField.tagSettingsLock.Lock() s.tagSettingsLock.Lock()
defer structField.tagSettingsLock.Unlock() defer s.tagSettingsLock.Unlock()
for key, value := range structField.TagSettings { for key, value := range s.TagSettings {
clone.TagSettings[key] = value clone.TagSettings[key] = value
} }