+++
+++

:source-highlighter: pygments
:source-language: go

== Golang

https://golang.org/[Golang] is a modern programming language that can
compiles to static binaries for most common platforms. This can result
in incredibly small docker images as you can build it from `scratch`.

I'm increasing using Golang in favour of Java, Kotlin or Python for
writing services.

=== Handling interrupts

Use the `signal` package to receive signals and put them
into a channel:

[source]
----
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
----

Then at the end of the main method you can perform a
blocking read on the channel:

[source]
----
<-c
----

=== Libraries

- https://github.com/gorilla/mux[gorilla/max], HTTP request router and despatcher
- https://github.com/gorilla/csrf[gorilla/csrf], CSRF middleware
- https://github.com/jamiealquiza/envy/[envy], exposes flags as environment variables
- https://github.com/guregu/null[null], defines nullable types for use with both SQL and JSON

=== Useful references

- https://dave.cheney.net/practical-go/presentations/qcon-china.html[Practical Go]:
  "Real world advice for writing maintainable Go programs"
- https://leanpub.com/productiongo/read[Production Go] book