I have been teaching programming for a while, and recently, I started teaching to web students.
After a few months of teaching, I proposed to add Go to the program. And it’s not because I want them to be Go programmers.… Read more
Category: Design
Network proxy in 20 lines
Authentication, load balancing… You need a proxy ? Let’s do it in an idiomatic way.
It’s surprisingly easy ! …
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
It’s surprisingly easy ! …
Needs
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
Unmarshal JSON to non-empty interface
When you’re filling a struct by calling :
json.Unmarshal(buff, &yourStruct)It is not uncommon that your struct contains a non-empty interface.
type IElement interface { GetBody() string } type Message struct { Name string Provider string Elements []IElement }And of course, json.Unmarshal can’t automatically find matching structs to fill that []IElement.… Read more