2 tricky behaviors of “defer”

When discovering Golang, “defer” seems at first a little exotic.
Here is 2 situations with no obvious behavior. …

Function calling a function in defer

If you want to time a function, at first sight, that may be a good idea to do :
package main
import (
func main() {
	start := time.Now()
	defer fmt.Println(time.Since(start))
	time.Sleep(100 * time.Millisecond)
and… wrong.…
Read more

Add Websocket to your TCP service with minimal changes

Offer your users the possibility to connect by websocket ! It allows them to use your service from javascript code : * Javascript is very popular and lets you build prototypes very quickly
* It’s more easy to build a GUI with HTML than most desktop languages
* You can offer a true demonstration of your service directly on your website and… let me convince you that it’s very low-cost.…
Read more

Network proxy in 20 lines

Authentication, load balancing… You need a proxy ? Let’s do it in an idiomatic way.
It’s surprisingly easy ! …


We need to handle 2 connections : the User and the Server. Story :
1- The User connects to the Proxy
2- The Proxy connects to the Server
3- The Proxy sent messages from the Client to the Server, and from the Server to the Client (transparently) We don’t speak about the specific treatment of the proxy (authentication, load balancing …) you wish to do.…
Read more