LintFix: Make receiver name of structField consistent (#2164)

* Make receiver name of structField consistent

* Change s to sf
This commit is contained in:
David Zhang 2019-01-02 21:27:17 +08:00 committed by Jinzhu
parent ac6c89ec0c
commit e2cfd6be3b
1 changed files with 33 additions and 33 deletions

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
@ -70,52 +70,52 @@ type StructField struct {
} }
// TagSettingsSet Sets a tag in the tag settings map // TagSettingsSet Sets a tag in the tag settings map
func (s *StructField) TagSettingsSet(key, val string) { func (sf *StructField) TagSettingsSet(key, val string) {
s.tagSettingsLock.Lock() sf.tagSettingsLock.Lock()
defer s.tagSettingsLock.Unlock() defer sf.tagSettingsLock.Unlock()
s.TagSettings[key] = val sf.TagSettings[key] = val
} }
// TagSettingsGet returns a tag from the tag settings // TagSettingsGet returns a tag from the tag settings
func (s *StructField) TagSettingsGet(key string) (string, bool) { func (sf *StructField) TagSettingsGet(key string) (string, bool) {
s.tagSettingsLock.RLock() sf.tagSettingsLock.RLock()
defer s.tagSettingsLock.RUnlock() defer sf.tagSettingsLock.RUnlock()
val, ok := s.TagSettings[key] val, ok := sf.TagSettings[key]
return val, ok return val, ok
} }
// TagSettingsDelete deletes a tag // TagSettingsDelete deletes a tag
func (s *StructField) TagSettingsDelete(key string) { func (sf *StructField) TagSettingsDelete(key string) {
s.tagSettingsLock.Lock() sf.tagSettingsLock.Lock()
defer s.tagSettingsLock.Unlock() defer sf.tagSettingsLock.Unlock()
delete(s.TagSettings, key) delete(sf.TagSettings, key)
} }
func (structField *StructField) clone() *StructField { func (sf *StructField) clone() *StructField {
clone := &StructField{ clone := &StructField{
DBName: structField.DBName, DBName: sf.DBName,
Name: structField.Name, Name: sf.Name,
Names: structField.Names, Names: sf.Names,
IsPrimaryKey: structField.IsPrimaryKey, IsPrimaryKey: sf.IsPrimaryKey,
IsNormal: structField.IsNormal, IsNormal: sf.IsNormal,
IsIgnored: structField.IsIgnored, IsIgnored: sf.IsIgnored,
IsScanner: structField.IsScanner, IsScanner: sf.IsScanner,
HasDefaultValue: structField.HasDefaultValue, HasDefaultValue: sf.HasDefaultValue,
Tag: structField.Tag, Tag: sf.Tag,
TagSettings: map[string]string{}, TagSettings: map[string]string{},
Struct: structField.Struct, Struct: sf.Struct,
IsForeignKey: structField.IsForeignKey, IsForeignKey: sf.IsForeignKey,
} }
if structField.Relationship != nil { if sf.Relationship != nil {
relationship := *structField.Relationship relationship := *sf.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() sf.tagSettingsLock.Lock()
defer structField.tagSettingsLock.Unlock() defer sf.tagSettingsLock.Unlock()
for key, value := range structField.TagSettings { for key, value := range sf.TagSettings {
clone.TagSettings[key] = value clone.TagSettings[key] = value
} }