Go Icon

Go

Go is a programming language built to resemble a simplified version of the C programming language.
331 Stories
All Topics

Raul Jordan rauljordan.com

This is why Go’s error handling is awesome

// In controllers/user.go
if err := database.CreateUser(); err != nil {
    log.Errorf("Could not create user: %v", err)
}

// In database/user.go
func CreateUser() error {
    if err := db.SQLQuery(userExistsQuery); err != nil {
        return fmt.Errorf("could not check if user already exists in db: %v", err)
    }
    ...
}

// In database/sql.go
func SQLQuery() error {
    if err := sql.Connected(); err != nil {
        return fmt.Errorf("could not establish db connection: %v", err)
    }
    ...
}

// in sql/sql.go
func Connected() error {
    if noInternet {
        return errors.New("no internet connection")
    }
    ...
}

The beauty of the code above is that each of these errors are completely namespaced by their respective function, are informative, and only handle responsibility for what they are aware of. This sort of error chaining using fmt.Errorf("something went wrong: %v", err) makes it trivial to build awesome error messages that can tell you exactly what went wrong based on how you defined it.

Patrick DeVivo github.com

Using SQL to query git repos

gitqlite is a tool for running SQL queries on git repositories. It implements SQLite virtual tables and uses go-git. It’s meant for ad-hoc querying of git repositories on disk through a common interface (SQL), as an alternative to patching together various shell commands.

Mine your repo’s history for goodies. Here’s how to get commit count by author email:

SELECT author_email, count(*) FROM commits GROUP BY author_email ORDER BY count(*) DESC

Jon Bodner capitalone.com

Go is boring...and that’s fantastic!

Jon Bodner shared a deep dive into why the world depends on simple, reliable, well-understood technologies like Go.

The one exciting thing that Go has is built-in concurrency support via goroutines, channels, and select. However, it is based on ideas from CSP, communicating sequential processes, which was first described in 1978.

This doesn’t sound like a programming language from the 21st century, does it?

And yet, Go is the 3rd most wanted and (maybe not coincidentally) the 3rd highest paying language, according to Stack Overflow. Every startup in Silicon Valley is using Go to build their infrastructure. Docker, Kubernetes, etcd, Terraform, Vault, Consul, Traefik and lots of other cutting-edge projects are written in Go. So what’s going on? Why is everyone interested in this boring language?

As a fun aside, I searched the Go Time transcripts for the word “boring” and found this gem from Kelsey Hightower on Go Time #114

When infrastructure gets boring, something else will become exciting above it.

…which makes sense why Go being boring is fantastic, because there’s so many exciting things being built with it.

Kubernetes github.com

Kubernetes multi-cluster deployment automation service

Application deployment and management should be automated, auditable, and easy to understand and that’s what beetle tries to achieve in a simple manner. Beetle automates the deployment and rollback of your applications in a multi-cluster, multi-namespaces kubernetes environments. Easy to integrate with through API endpoints & webhooks to fit a variety of workflows.

Kubernetes multi-cluster deployment automation service

Go github.com

Go+ is like Go if it were built for data scientists

This new data-science-focused language is fully compatible with Go*, but streamlines things for data science use. It simplifies common scripting tasks. This in Go:

package main

func main() {
    a := []float64{1, 2, 3.4}
    println(a)
}

Becomes this in Go+:

a := [1, 2, 3.4]
println(a)

And adds features like list comprehensions for easier data processing:

a := [1, 3, 5, 7, 11]
b := [x*x for x <- a, x > 3]
println(b) // output: [25 49 121]

mapData := {"Hi": 1, "Hello": 2, "Go+": 3}
reversedMap := {v: k for k, v <- mapData}
println(reversedMap) // output: map[1:Hi 2:Hello 3:Go+]

It can be compiled directly to bytecode or transpiled into Go code. Give it a go on the playground.

*I almost described it as a “superset” of Go, but I’m not 💯 if that’s true.

Go github.com

Rob Pike's toy Lisp interpreter in Go

This program was a joy to put together. Its purpose was fun and education, and in no way to create a modern or even realistic Lisp implementation. The goal was to turn that marvelous page 13 into a working interpreter using clean, direct Go code.

If you’re interested in what one of Go’s creators believes is “clean, direct Go code”, then you’re interested in this repo.

Ian Lance Taylor blog.golang.org

The next step for Go generics

Ian Lance Taylor:

It’s been almost a year since we last wrote about the possibility of adding generics to Go. It’s time for an update.

Jump straight to the updated design draft or read Ian’s post for details on the new experimental translation tool and the the kinds of feedback they are seeking. If you’re only interested in a release date for the final implementation:

if everybody is completely happy with the design draft and it does not require any further adjustments, the earliest that generics could be added to Go would be the Go 1.17 release, scheduled for August 2021.

Note: that’s the earliest it will be. This is not a guarantee by any means.

Go github.com

A lightweight, high-speed immutable database for systems and applications

With immudb you can track changes in sensitive data in your transactional databases and then record those changes permanently in a tamperproof immudb database. This allows you to keep an indelible history of sensitive data, for example debit/credit card transactions.

There are so many options for storing data these days. If you haven’t heard Go Time’s excellent episode on databases yet, Jaana does a great job of explaining some of the trade-offs.

Go github.com

Learn Go with this huge repository of examples, exercises, and quizzes

This repository contains the examples, exercises, and quizzes for my Go course: Learn Go Programming: Complete Bootcamp Course. However, even without the course, using this repository, you can learn a great deal of information about Go. Inside, there are thousands of examples, exercises and quizzes.

You’re welcome to contribute your own exercises, quizzes and wiki.

Christian Scott christianfscott.com

Making Rust as fast as Go (fake news)

Is this more proof of Cunningham’s law, which says, “The best way to get the right answer on the Internet is not to ask a question; it’s to post the wrong answer.”

Update: as some keen HN commenters have pointed out, it looks like the rust program is not actually equivalent to the go program. The go program parses the string once, while the rust program parses it repeatedly inside every loop. It’s quite late in Sydney as I write this so I’m not up for a fix right now, but this post is probably Fake News.

Read Christian’s post then have fun in the comments and discussions on HN and Reddit analyzing his hypothesis, which includes a repo of code to backup his ideas.

Go caddyserver.com

Caddy 2 is production-ready

Caddy has been around for a while, so this is a major release for the project. Hard to believe this is true today (emphasis added)

Still the only web server to use TLS automatically and by default.

Caddy 2’s new architecture was inspired by 5 years of experience with Caddy 1 and took 14 months to design. There’s a lot here, so we probably need to get the team on The Changelog or Go Time to discuss in depth.

Todd Kulesza blog.golang.org

Go developer survey 2019 results

Good news! For 2019 there were 10,975 responses to the survey — that’s almost twice as many as last year. Here are few major findings from the results, but of course, you should dig in because they make it really easy to scan and grok the details.

  • The demographics of our respondents are similar to Stack Overflow’s survey respondents, which increases our confidence that these results are representative of the larger Go developer audience.
  • A majority of respondents use Go every day, and this number has been trending up each year.
  • Respondents are using Go to solve similar problems, particularly building API/RPC services and CLIs, regardless of the size of organization they work at.
  • Most teams try to update to the latest Go release quickly; when third-party providers are late to support the current Go release, this creates an adoption blocker for developers.
  • Almost everyone in the Go ecosystem is now using modules, but some confusion around package management remains.
  • VS Code and GoLand have continued to see increased use; they’re now preferred by 3 out of 4 respondents.

Ilija Eftimov ieftimov.com

Understanding bytes in Go by building a TCP protocol

Ilija Eftimov:

For folks that do not have experience with lower level languages, understanding bytes and how to work with them can be challenging.

That’s why I wrote this article, taking a simple idea such as a Slack chat, turning the interactions (join/leave channel, send message to channel or user, etc) into a TCP protocol. Then I show the reader how they can implement the protocol in Go, by building a concurrent TCP server and learn more about bytes and working with bytes in the process.

I love it when people take things we do understand (like basic Slack interactions) and use them to teach us something we don’t understand (how to build a TCP protocol).

Productivity github.com

Declaratively configure your Gmail filters

If you use (and abuse) Gmail’s filters in order to wrangle your inbox, this tool might help you keep your sanity as you maintain them over time.

This utility helps you generate and maintain Gmail filters in a declarative way. It has a Jsonnet configuration file that aims to be simpler to write and maintain than using the Gmail web interface, to categorize, label, archive and manage your inbox automatically.

Go blog.golang.org

Go and the Go community during this pandemic

In this post Carmen Andoh, Russ Cox, and Steve Francia share important notes about how the pandemic is affecting the Go community, what they’re doing to help, what you can do to help, and upcoming plans for Go itself.

Go always comes second to more basic concerns like personal and family health and safety. Around the world, the past couple months have been terrible, and we are still at the start of this awful pandemic. There are days when it seems like working on anything related to Go should be considered a serious priority inversion.

But after we’ve done all we can to prepare ourselves and our families for whatever is coming, getting back to some approximation of a familiar routine and normal work is a helpful coping mechanism. In that spirit, we intend to keep working on Go and trying to help the Go community as much as we can.

Go github.com

GoTube – a very simple command line tool for downloading YouTube videos

This repository contains a single-file implementation of YouTube video downloader written in Go. It does not require any third-party packages, only built-in packages from the standard library. The code is compact and easily-readable.

Nowhere near the features of youtube-dl (which is like a swiss army knife for downloading videos off the internet), but cool nonetheless. You can read the entirety of GoTube’s source code in a single sitting, which makes it great for learning and tinkering.

0:00 / 0:00