Rediscovering Golang with "pullpigo", a small hobby-project
I wanted to learn Go (the programming language). My plan was to implement a CLI tool for displaying information on GitHub pull requests. I thus created a small project in GitHub: pullpigo, in order to display event counters about GitHub pull requests via GitHub's public API.
Note that I have already implemented this CLI tool in other programming languages that I wanted to learn: in Clojure (see hubstats), Kotlin (see pullpitoK) and Rust (see pullpito).
Native executables are fast 🚀
Let's compile pullpigo:
$ go clean
$ time go build
go build 1.05s user 0.58s system 105% cpu 1.559 total
Then run it:
time ./pullpigo -repo=vidal-community/atom-jaxb
GitHub repository 'vidal-community/atom-jaxb'
2 events created by amairi
1 events created by fchetouani
6 events created by AElMehdiVidal
3 events created by jcgay
./pullpigo -repo=vidal-community/atom-jaxb 0.07s user 0.03s system 20% cpu 0.482 total
Now compare these build & run times with a similar Kotlin project (pullpitoK):
$ ./gradlew clean
$ time ./gradlew build --quiet
./gradlew build --quiet 1.37s user 0.17s system 39% cpu 3.932 total
$ time ./gradlew run --quiet --args "vidal-community/atom-jaxb"
pull requests for "vidal-community/atom-jaxb" ->
opened per author
amairi: 1
commented per author
AElMehdiVidal: 1
jcgay: 1
closed per author
./gradlew run --quiet --args "vidal-community/atom-jaxb" 1.37s user 0.18s system 62% cpu 2.473 total
Fast compilation + fast runtime = ❤️
Golang SDK already includes many common utilities 📦
In order to call GitHub's REST API v3 'events' API, all I needed was: a HTTP client, a JSON parser and a test framework. Good news, all are included in the Golang SDK: testing, HTTP client and JSON parsing.
As a consequence, I implemented my project with zero dependencies!
Other goodies have I appreciated from by Java background:
-
code formatting is included! Its' simple as
go fmt
. No need to find and configure an external code formatting tools. -
code linter is included! Just install https://github.com/golang/linttype and run the
golint
command. No need to find and configure an external code formatting tools. (to be honest, the linter did not help when coding pullpigo but it's so cool that code linter is provided).
Other opportunities 😎
Coding this small hobby project has also been an opportunity to try and learn other tools. In my case, I could:
-
Use Visual Studio Code, an Integrated Development Environment that I don't use at work.
-
Use GitHub Actions for Continuous Integration: every git commit pushed on GitHub triggers a compilation & test check. It was the first time I used GitHub Actions, it was very easy (it only took a few minutes) to use it for my needs, and it's free.
The last positive thing about learning a programming language is that you can discuss and learn with people you know.
In my case, my "Golang friends" have been:
-
Jean-Christophe who helped me to fix my JSON parsing issues. 😅
-
Florent who gave me pointers on cool libraries: testing/quick for property-based testing, ginkgo for BDD-style tests and gomega for test assertions. I have to try them out! 😎
What's next? 🔮
Some ideas:
-
Make pullpigo's output more useful. For example, I could make it display counters for events like "pull request created", "pull request merged" etc.
-
Retrieve data from GitHub's GraphQL API v4 in order to by-pass the limitation of number of events (GitHub's REST API v3 'events' API only returns the last 300 events).
-
Use some dependencies for testing (easier assertions, property-based-testing etc.) and take this opportunity to discover dependencies in Golang.
We'll see!