suspicious assignment to a by-value method receiver
51}
52
53func (t UserModel) SetConn(con db.Connection) UserModel {
54 t.Conn = con 55 return t
56}
57
suspicious assignment to a by-value method receiver
56}
57
58func (t UserModel) WithTx(tx *sql.Tx) UserModel {
59 t.Tx = tx 60 return t
61}
62
suspicious assignment to a by-value method receiver
109
110func (t UserModel) Template(str string) string {
111 if t.cacheReplacer == nil {
112 t.cacheReplacer = strings.NewReplacer("{{.AuthId}}", strconv.Itoa(int(t.Id)),113 "{{.AuthName}}", t.Name, "{{.AuthUserName}}", t.UserName)
114 }
115 return t.cacheReplacer.Replace(str)
suspicious assignment to a by-value method receiver
233
234// UpdateAvatar update the avatar of user.
235func (t UserModel) ReleaseConn() UserModel {
236 t.Conn = nil237 return t
238}
239
suspicious assignment to a by-value method receiver
239
240// UpdateAvatar update the avatar of user.
241func (t UserModel) UpdateAvatar(avatar string) {
242 t.Avatar = avatar243}
244
245// WithRoles query the role info of the user.
suspicious assignment to a by-value method receiver
256 }
257
258 if len(t.Roles) > 0 {
259 t.Level = t.Roles[0].Slug260 t.LevelName = t.Roles[0].Name
261 }
262
suspicious assignment to a by-value method receiver
257
258 if len(t.Roles) > 0 {
259 t.Level = t.Roles[0].Slug
260 t.LevelName = t.Roles[0].Name261 }
262
263 return t
suspicious assignment to a by-value method receiver
383 "avatar": avatar,
384 })
385
386 t.Id = id387 t.UserName = username
388 t.Password = password
389 t.Avatar = avatar
suspicious assignment to a by-value method receiver
384 })
385
386 t.Id = id
387 t.UserName = username388 t.Password = password
389 t.Avatar = avatar
390 t.Name = name
suspicious assignment to a by-value method receiver
385
386 t.Id = id
387 t.UserName = username
388 t.Password = password389 t.Avatar = avatar
390 t.Name = name
391
suspicious assignment to a by-value method receiver
386 t.Id = id
387 t.UserName = username
388 t.Password = password
389 t.Avatar = avatar390 t.Name = name
391
392 return t, err
suspicious assignment to a by-value method receiver
387 t.UserName = username
388 t.Password = password
389 t.Avatar = avatar
390 t.Name = name391
392 return t, err
393}
suspicious assignment to a by-value method receiver
423 "password": password,
424 })
425
426 t.Password = password427 return t
428}
429
suspicious assignment to a by-value method receiver
511
512// MapToModel get the user model from given map.
513func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
514 t.Id, _ = m["id"].(int64)515 t.Name, _ = m["name"].(string)
516 t.UserName, _ = m["username"].(string)
517 t.Password, _ = m["password"].(string)
suspicious assignment to a by-value method receiver
512// MapToModel get the user model from given map.
513func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
514 t.Id, _ = m["id"].(int64)
515 t.Name, _ = m["name"].(string)516 t.UserName, _ = m["username"].(string)
517 t.Password, _ = m["password"].(string)
518 t.Avatar, _ = m["avatar"].(string)
suspicious assignment to a by-value method receiver
513func (t UserModel) MapToModel(m map[string]interface{}) UserModel {
514 t.Id, _ = m["id"].(int64)
515 t.Name, _ = m["name"].(string)
516 t.UserName, _ = m["username"].(string)517 t.Password, _ = m["password"].(string)
518 t.Avatar, _ = m["avatar"].(string)
519 t.RememberToken, _ = m["remember_token"].(string)
suspicious assignment to a by-value method receiver
514 t.Id, _ = m["id"].(int64)
515 t.Name, _ = m["name"].(string)
516 t.UserName, _ = m["username"].(string)
517 t.Password, _ = m["password"].(string)518 t.Avatar, _ = m["avatar"].(string)
519 t.RememberToken, _ = m["remember_token"].(string)
520 t.CreatedAt, _ = m["created_at"].(string)
suspicious assignment to a by-value method receiver
515 t.Name, _ = m["name"].(string)
516 t.UserName, _ = m["username"].(string)
517 t.Password, _ = m["password"].(string)
518 t.Avatar, _ = m["avatar"].(string)519 t.RememberToken, _ = m["remember_token"].(string)
520 t.CreatedAt, _ = m["created_at"].(string)
521 t.UpdatedAt, _ = m["updated_at"].(string)
suspicious assignment to a by-value method receiver
516 t.UserName, _ = m["username"].(string)
517 t.Password, _ = m["password"].(string)
518 t.Avatar, _ = m["avatar"].(string)
519 t.RememberToken, _ = m["remember_token"].(string)520 t.CreatedAt, _ = m["created_at"].(string)
521 t.UpdatedAt, _ = m["updated_at"].(string)
522 return t
suspicious assignment to a by-value method receiver
517 t.Password, _ = m["password"].(string)
518 t.Avatar, _ = m["avatar"].(string)
519 t.RememberToken, _ = m["remember_token"].(string)
520 t.CreatedAt, _ = m["created_at"].(string)521 t.UpdatedAt, _ = m["updated_at"].(string)
522 return t
523}
suspicious assignment to a by-value method receiver
518 t.Avatar, _ = m["avatar"].(string)
519 t.RememberToken, _ = m["remember_token"].(string)
520 t.CreatedAt, _ = m["created_at"].(string)
521 t.UpdatedAt, _ = m["updated_at"].(string)522 return t
523}
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
}