mneverov / protectedby

Checks that access to shared resources is protected

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protectedby

Checks that access to shared resources is protected.

go install github.com/mneverov/protectedby@latest

When a shared resource (field) has a comment with protected by <lock_name>, access to this field will be validated to ensure it is guarded by the specified lock.

See code snippet:

type someStruct struct {
    // i is protected by mu. 
    i int
    mu sync.Mutex
}

func foo() {
    s := someStruct{}
    s.i = 42 // not protected access to shared field i, use s.mu.Lock()
}

For more info see tests.

About

Checks that access to shared resources is protected

License:MIT License


Languages

Language:Go 100.0%