Netlify, the hosting and web platform, allows you to create "functions" along with their CDN. These functions are hosted on AWS’ Lambda and can be accessible via a URL. So you can create static sites, with extra ability and dynamism (like we use on this site).
We wanted to share a post giving an example how to write one of these functions in Go. The aim of the code (below) is to return the version of golang.
We installed the Netlify cli to make our lives a little easier.
Create our new function, we called it go-version
Update the code (see below for file path and code)
Recover from a Panic
How to catch a panic error when it’s thrown? That’s what this post hopes to answer.
Go has a built in recover() function which allows you to pick up and run some code when a panic is thrown. This can be useful for regaining execution of your program, or allowing the panic to happen, but to clean up state (like files) before your program closes.
If you are curious what the structure of a panic is, see it’s docs here.
How to Format Your Golang Code
Whether you agree with it or not, Go defines a code style at a language level (which I love), and not different styles per project - or having the style as an afterthought! This means there’s very little opinion or conflict when moving between projects so it’s easy. This is very important to Go, as it stresses clarity and consistency as some of the most important factors of code style.