Hello, I'm Ganesh Kumar. I'm working on git-lrc: a Git hook for Checking AI generated code.AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
In my previous post, I explained how closure works.
In this article we will understand how to method works.
Method
Method is a function with a receiver.
This works like a class method in other languages.
Here is the example of method.
let's define a struct value and add method to it.
package main
import "fmt"
type value struct {
X, Y int
}
func (v value) add() int {
return v.X + v.Y
}
func main() {
val := value{1,2}
fmt.Println(val.add())
val2 := &value{1,2}
fmt.Println(val2.add())
}
Output:
gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go
3
This is a simple example of method.
Pointer receiver
Pointer receiver is used to modify the value of the struct.
package main
import "fmt"
type value struct {
X, Y int
}
func (v *value) add() int {
v.X += 1
v.Y += 1
return v.X + v.Y
}
func main() {
val := value{1,2}
fmt.Println(val.add())
println(val.X,val.Y)
}
Output:
gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go
3
2 3
From this we can see that pointer receiver is used to modify the value of the struct.
Conclusion
In this article we understood how method works and how pointer receiver is used to modify the value of the struct.
π Check out: git-lrc
Any feedback or contributors are welcome! Itβs online, open-source, and ready for anyone to use.
β Star it on GitHub:
HexmosTech
/
git-lrc
Free, Unlimited AI Code Reviews That Run on Commit
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
See It In Action
See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements
git-lrc-intro-60s.mp4
Why
- π€ AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
- π Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
- π Build a habit, ship better code. Regular review β fewer bugs β more robust code β better results in your team.
- π Why git? Git is universal. Every editor, every IDE, every AIβ¦

Top comments (0)