The Best Go Content on the Internet


How to Tokenize Complex Strings with Lexmachine

Contributed by

This article is about using lexmachine to tokenize strings (split up into component parts) in the Go (golang) programming language. If you find yourself processing a complex file format or network protocol this article will walk you through how to use lexmachine to process both accurately and quickly. If you need more help after reading this article take a look at the documentation, a tutorial, or an explainer article on how it all works.

Read more...

Web Sessions and Common User Workflows - A Foundation for Go-Based Websites

Contributed by

Go is widely used to implement microservices and APIs. And for those wishing to set up a dynamic website without resorting to, say, Ruby or PHP, Go offers a lot of tools out of the box. The use of net/http and html/templates can get you very far already. As soon as a user needs to be identified across multiple HTTP requests, you need to start thinking about web sessions. They can be thought of as storage units assigned to a user, which persist across requests.

Read more...

Parsing with ANTLR 4 and Go

Contributed by

What is ANTLR? ANTLR (ANother Tool for Language Recognition), is an ALL(*) parser generator. In layman’s terms, Antlr, creates parsers in a number of languages (Go, Java, C, C#, Javascript), that can process text or binary input. The generated parser provides a callback interface to parse the input in an event-driven manner, which can be used as-is, or used to build parse trees (a data structure representing the input).

Read more...

Property Based Testing

Contributed by

Useful Programs I’ll start this post with a bold but fairly uncontroversial statement: Programs that do not interact with the outside world are useless - they do nothing except consume cycles. A corollary of this is that pure functional programming is useless. Here is a (mostly) pure functional program written in Go that does absolutely nothing: package foo func incr(i int) int { return i+1 } func decr(i int) int { return i-1 } func foo() { decr(incr(0)) } While obviously there are other things that make a program useful, the most fundamental thing that makes a program useful is that it needs to interact with things outside itself.

Read more...

Custom JSON unmarshaler for a GraphQL client

Contributed by

In this post, I will tell a story of how I had to build a custom JSON unmarshaler for the needs of a GraphQL client library in Go. I’ll start with the history of how everything started, build motivation for why a custom JSON marshaler was truly needed, and then describe how it was implemented. This is going to be a long journey, so strap yourself in, and here we go!

Read more...

Repeatable and Isolated Development Environments for Go

Contributed by

One of the common criticisms of the GOPATH is that it is hard to create isolated development environments without resorting to hacks, bash scripts, multiple GOPATH settings, or other trickery. Generally, I don’t often have too many problems with GOPATH, but when I do they are frustrating and hard to figure out. An example: Your dependency manager copies deps from your GOPATH into your project’s vendor folder. But the dependency it copies is your fork, not the upstream, so the vendored package isn’t what you expected.

Read more...

Managing Dependencies, Forks, and Code Patches with Dep

Contributed by

A few months ago, we switched over to using dep to manage dependencies for Veneur. We were excited to discover that dep provided a straightforward workflow for a longstanding problem in Go development: managing forks of dependencies and contributions to upstream projects. This is a common problem with dependency management. Some tools attempt to provide workflows for managing it, and in my experience, the workflow dep has chosen is the cleanest I’ve seen.

Read more...

A Tale of Two `rand`s

Contributed by

I had always been a bit confused as to how the crypto/rand package and the math/rand package were related, or how they were expected to work (together). Is this something that everyone else already grokked, or is that just my impostor syndrome talking? Well, one day I decided to see if I could defeat my ignorance, and this blog post is the result of that investigation. The math One If you’ve ever poked around in the math/rand package, you might agree that it presents a fairly convenient API.

Read more...

Creating Your Own Bot Experience with go-sarah

Contributed by

Chat tools have been good friends of developers. On chat tools we share our thoughts, problems, solutions, jokes, and pretty much everything we do as software engineers. And when some kind of tasks can be done in the extension of daily chat conversation, chat becomes even more comfortable yet powerful place to stay. That is why I think many developers eager to customize their chat experience with bot frameworks. In this article I am going to introduce a new golang-based bot framework, go-sarah, along with its notable characteristics and components.

Read more...

Minimal Perfect Hash Functions

Contributed by

A regular hash function turns a key (a string or a number) into an integer. Most people will know them as either the cryptographic hash functions (MD5, SHA1, SHA256, etc) or their smaller non-cryptographic counterparts frequently encountered in hash tables (the map keyword in Go). Collisions, where two input values hash to the same integer, can be an annoyance in hash tables and disastrous in cryptography. Collisions can happen with any standard hash function and any number of keys.

Read more...