How can a simple contribution to a library impact thousands of programs around the world? And why will this change become obsolete after the Go 1.26 release? These and a few other questions I’ll answer in detail in this post.
TL;DR: I replaced four helper functions (String, Bool, Int, Int64) with a single generic Ptr[T] function in
google/go-github
, affecting 10K+ projects.
Ironically, Go 1.26’s enhanced new builtin will make this pattern unnecessary.
The contribution
Replacing four helper routines with one generic function github.Ptr in
PR
in the
google/go-github
project is my largest and most impactful contribution ever.
And here’s why I think so.
google/go-github
The google/go-github, the Go library for accessing the GitHub REST API, is a widely popular package with over
11K stars
on GitHub.
GitHub shows
that it’s used by more than 10K programs across the GitHub ecosystem.
The
Go Reference
shows that this package is imported more than 7.5K times.
However, this understates the real usage since the library has over 80 major versions, each tracked separately.
SourceGraph
lists 10K+ go-github imports
and it’s not a limit.
Also, we don’t know how many closed-source libraries import go-github.
The
google/go-github
is a
backbone
for the
GitHub MCP server
(26K stars).
The MCP server is used by every AI agent that is doing something on GitHub.
Technical details
From a technical perspective, replacing a few helper functions with one generic function is not a big deal. But these helper functions are used by everyone who interacts with the GitHub API. This means millions of developers benefit from this small change.
Taking an address of a constant
In Go, there is no simple way to create pointers to non-zero bool/numeric/string values. For example, the following code does not compile:
var a = &1234 // invalid operation: cannot take address of 1234 (untyped int constant)
var b = &true // invalid operation: cannot take address of true (untyped bool constant)
var c = &"hi" // invalid operation: cannot take address of "hi" (untyped string constant)
To overcome this, we should use an additional variable which leads to more verbose code:
var num = 1234
var a = &num
var tr = true
var b = &tr
var str = "hi"
var c = &str
The Go101 tells, that we can also use these one-liners via these constructs :
var a = &(&[1]int{1234})[0]
var b = &(&[1]bool{true})[0]
var c = &(&[1]string{"hi"})[0]
Or slightly less efficient :
var a = &([]int{1234})[0]
var b = &([]bool{true})[0]
var c = &([]string{"hi"})[0]
But using an anonymous functions is the most popular way to achieve that:
var a = func(v int) *int { return &v }(1234)
var b = func(v bool) *bool { return &v }(true)
var c = func(v string) *string { return &v }("hi")
Helpers for optional values in go-github
Optional values are heavily used in google/go-github functions.
The authors of google/go-github implemented the third way but moved to named functions to achieve that:
func Int(v int) *int { return &v }
func Bool(v bool) *bool { return &v }
func Int64(v int64) *int64 { return &v }
func String(v string) *string { return &v }
This example is from the README :
repo := &github.Repository{
Name: github.String("foo"),
Private: github.Bool(true),
}
client.Repositories.Create(ctx, "", repo)
My pull request to replace helper functions with github.Ptr
My PR replaces these four helper functions with one that uses Go 1.18 generics:
func Ptr[T any](v T) *T { return &v }
And we can use it as:
var a = Ptr(1234)
var b = Ptr(true)
var c = Ptr("hi")
In google/go-github :
repo := &github.Repository{
Name: github.Ptr("foo"),
Private: github.Ptr(true),
}
client.Repositories.Create(ctx, "", repo)
To be more precise, it should restrict also T to only four types used in google/go-github:
func Ptr[T bool | int | int64 | string](v T) *T { return &v }
But we decided to use any (interface{}).
This change is only adding one line and 20 lines of tests. But PR ’s changes are 15K additions and 15K deletions. Why is that big?
It’s because we need to replace github.String/github.Int/github.Int64/github.Bool to github.Ptr in all existing examples and tests.
Why Ptr will become obsolete in Go 1.26
Interestingly, just as my contribution unified the helper functions into a single generic Ptr, the Go team is about to make it obsolete.
The Ptr function is
highly popular
and exists in every major project:
- kubernetes
(called
ptr.To) - tailscale
- gitlab-org/api/client-go
- getkin/kin-openapi (my PR to add it )
But Go
1.26
allows passing an expression to the new builtin function.
It is going to
be released
in two weeks, but we can try it in the
Gotip Playground
.
So, we can simplify our initial example to the following :
var a = new(1234)
var b = new(true)
var c = new("hi")
And in google/go-github :
repo := &github.Repository{
Name: new("foo"),
Private: new(true),
}
client.Repositories.Create(ctx, "", repo)
Conclusion
Open source contributions can be small and simple yet have a huge impact on the world. My one-line generic function is now used by 10K+ projects and powers every AI agent interacting with GitHub.
Yes, Go 1.26 will make Ptr obsolete — but that’s the nature of software.
The real value was not just the code. It was finding an opportunity to simplify something used by millions.
Keep reading release notes, keep contributing, and don’t be afraid to make small changes. Sometimes they matter more than you think.
