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 what are maps and how to create them.
Now let's see how anonymous functions created and understand how it works.
Anonymous functions
We assign a function to a variable and then call it.
package main
import "fmt"
func main() {
data := func() {
fmt.Println("Hello World")
}
data()
}
Hello World
Similarly we can also pass arguments to the anonymous function.
package main
import "fmt"
func main() {
data := func(a,b string) {
fmt.Println(a,b)
}
data("dev","to")
}
Output:
dev to
Passing function as an argument
We are passing a function as an argument to another function.
package main
import "fmt"
func anonymous(a func()) {
a()
}
func main() {
data := func() {
fmt.Println("Hello World")
}
anonymous(data)
}
Output:
Hello World
If we want to pass arguments to the anonymous function, we can do it like this:
package main
import "fmt"
func anonymous(a func(string,string)) {
a("dev","to")
}
func main() {
data := func(a,b string) {
fmt.Println(a,b)
}
anonymous(data)
}
As is the print statement is inside the anonymous function, it is printing the values passed to it.
Output:
dev to
Conclusion
We understood how the anonymous functions are created and how to pass them as arguments to another function.
As go has the feature of passing functions as arguments to another function, go provides a feature called closure.
π 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β¦
https://github.com/golang/go/blob/master/src/runtime/slice.go

Top comments (0)