Go

Go

Made by DeepSource

Usage of both value and pointer receivers GO-W1029

Anti-pattern
Major

(Go's FAQ)[https://go.dev/doc/faq#methodsonvaluesorpointers] recommends that method receivers should be consistent. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used. This is because value and pointer receivers have different method sets.

Bad practice

package main

type foo struct {
    a int
}

func (f foo) a() {}

func (f *foo) b() {
    f.a = 10
}

Recommended

package main

type foo struct {
    a int
}

func (f *foo) a() {}

func (f *foo) b() {
    f.a = 10
}