Skip to content

geraldywy/go-refcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-refcheck

go install github.com/geraldywy/go-refcheck

go-refcheck reports function receivers where use of large structs are passed by value.

Why?

Passing large structs as function receivers generates a copy in memory to work off of. This can create potential issues with the progam's memory heap.

Also, see copyfighter for a similar linter.

Example

type MyLargeStruct struct {
    A string
    B int64
    C float64
    D string
    E *bool
}

func (l *MyLargeStruct) Okay() bool {
    return *l.E
}

func (l MyLargeStruct) NotOkay() bool {
    return *l.E
}

The function NotOkay is flagged as follows:

$ go-refcheck ./...

$ .../testdata/src/p/p.go:28:9: large struct "MyLargeStruct" passed by value to function receiver

More examples can be found in the testdata folder.

Flags

By default, large structs are assumed to be larger than 32 bytes, this value can be toggled with a max flag.

Eg: To only flag for large structs larger than 64 bytes:

go-refcheck -max 64 ./...

About

go-refcheck is a static linter for golang. It reports function receivers where use of large structs are passed by value.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages