suspicious assignment to a by-value method receiver
503 t.Avatar, _ = m["avatar"].(string)
504 t.RememberToken, _ = m["remember_token"].(string)
505 t.CreatedAt, _ = m["created_at"].(string)
506 t.UpdatedAt, _ = m["updated_at"].(string)507 return t
508}
suspicious assignment to a by-value method receiver
502 t.Password, _ = m["password"].(string)
503 t.Avatar, _ = m["avatar"].(string)
504 t.RememberToken, _ = m["remember_token"].(string)
505 t.CreatedAt, _ = m["created_at"].(string)506 t.UpdatedAt, _ = m["updated_at"].(string)
507 return t
508}
suspicious assignment to a by-value method receiver
501 t.UserName, _ = m["username"].(string)
502 t.Password, _ = m["password"].(string)
503 t.Avatar, _ = m["avatar"].(string)
504 t.RememberToken, _ = m["remember_token"].(string)505 t.CreatedAt, _ = m["created_at"].(string)
506 t.UpdatedAt, _ = m["updated_at"].(string)
507 return t
suspicious assignment to a by-value method receiver
500 t.Name, _ = m["name"].(string)
501 t.UserName, _ = m["username"].(string)
502 t.Password, _ = m["password"].(string)
503 t.Avatar, _ = m["avatar"].(string)504 t.RememberToken, _ = m["remember_token"].(string)
505 t.CreatedAt, _ = m["created_at"].(string)
506 t.UpdatedAt, _ = m["updated_at"].(string)
suspicious assignment to a by-value method receiver
499 t.Id, _ = m["id"].(int64)
500 t.Name, _ = m["name"].(string)
501 t.UserName, _ = m["username"].(string)
502 t.Password, _ = m["password"].(string)503 t.Avatar, _ = m["avatar"].(string)
504 t.RememberToken, _ = m["remember_token"].(string)
505 t.CreatedAt, _ = m["created_at"].(string)
suspicious assignment to a by-value method receiver
498func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
499 t.Id, _ = m["id"].(int64)
500 t.Name, _ = m["name"].(string)
501 t.UserName, _ = m["username"].(string)502 t.Password, _ = m["password"].(string)
503 t.Avatar, _ = m["avatar"].(string)
504 t.RememberToken, _ = m["remember_token"].(string)
suspicious assignment to a by-value method receiver
497// MapToModel get the user model from given map.
498func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
499 t.Id, _ = m["id"].(int64)
500 t.Name, _ = m["name"].(string)501 t.UserName, _ = m["username"].(string)
502 t.Password, _ = m["password"].(string)
503 t.Avatar, _ = m["avatar"].(string)
suspicious assignment to a by-value method receiver
496
497// MapToModel get the user model from given map.
498func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
499 t.Id, _ = m["id"].(int64)500 t.Name, _ = m["name"].(string)
501 t.UserName, _ = m["username"].(string)
502 t.Password, _ = m["password"].(string)
suspicious assignment to a by-value method receiver
408 "password": password,
409 })
410
411 t.Password = password412 return t
413}
414
suspicious assignment to a by-value method receiver
372 t.UserName = username
373 t.Password = password
374 t.Avatar = avatar
375 t.Name = name376
377 return t, err
378}
suspicious assignment to a by-value method receiver
371 t.Id = id
372 t.UserName = username
373 t.Password = password
374 t.Avatar = avatar375 t.Name = name
376
377 return t, err
suspicious assignment to a by-value method receiver
370
371 t.Id = id
372 t.UserName = username
373 t.Password = password374 t.Avatar = avatar
375 t.Name = name
376
suspicious assignment to a by-value method receiver
369 })
370
371 t.Id = id
372 t.UserName = username373 t.Password = password
374 t.Avatar = avatar
375 t.Name = name
suspicious assignment to a by-value method receiver
368 "avatar": avatar,
369 })
370
371 t.Id = id372 t.UserName = username
373 t.Password = password
374 t.Avatar = avatar
suspicious assignment to a by-value method receiver
256
257 if len(t.Roles) > 0 {
258 t.Level = t.Roles[0].Slug
259 t.LevelName = t.Roles[0].Name260 }
261
262 return t
suspicious assignment to a by-value method receiver
255 }
256
257 if len(t.Roles) > 0 {
258 t.Level = t.Roles[0].Slug259 t.LevelName = t.Roles[0].Name
260 }
261
suspicious assignment to a by-value method receiver
238
239// UpdateAvatar update the avatar of user.
240func (t UserModel) UpdateAvatar(avatar string) {
241 t.Avatar = avatar242}
243
244// WithRoles query the role info of the user.
suspicious assignment to a by-value method receiver
232
233// UpdateAvatar update the avatar of user.
234func (t UserModel) ReleaseConn() UserModel {
235 t.Conn = nil236 return t
237}
238
suspicious assignment to a by-value method receiver
108
109func (t UserModel) Template(str string) string {
110 if t.cacheReplacer == nil {
111 t.cacheReplacer = strings.NewReplacer("{{.AuthId}}", strconv.Itoa(int(t.Id)),112 "{{.AuthName}}", t.Name, "{{.AuthUserName}}", t.UserName)
113 }
114 return t.cacheReplacer.Replace(str)
suspicious assignment to a by-value method receiver
55}
56
57func (t UserModel) WithTx(tx *sql.Tx) UserModel {
58 t.Tx = tx 59 return t
60}
61
suspicious assignment to a by-value method receiver
50}
51
52func (t UserModel) SetConn(con db.Connection) UserModel {
53 t.Conn = con 54 return t
55}
56
Description
A method that modifies its receiver value can have undesired behavior. The modification can also be the root of a bug because the actual value receiver could be a copy of that used at the calling site. This rule warns when a method modifies its receiver.
Bad practice
type data struct {
num int
key *string
items map[string]bool
}
func (d data) vmethod() {
d.num = 8
}
Recommended
type data struct {
num int
key *string
items map[string]bool
}
func (d *data) vmethod() {
d.num = 8
}