+++
+++

: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 usling 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

=== Useful references

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