RSSAmplifier

Blog

Guillaume's Thoughts

Recent content on Guillaume's Thoughts

blog.charmes.netRSS feed ↗15 posts

Latest posts

Glide Cache and Docker

Intro Dependency management in Golang got a lot better since go1.5, however, we still need tools to manage it. For a long time, I used Godep which was working great, but handles everything based on your local GOPATH which result in massive change sets in git each time a different team member updates them, which makes the code review difficult. Here comes Glide . A “newcomer” which uses…

JSON Date management in Golang

TL;DR Arbitrary date unmarshal support + easily set marshal date format for both json and bson. The code and examples can be found here: https://github.com/simplereach/timeutils. Small example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 package main import ( 'encoding/json' 'fmt' 'os' 'github.com/simplereach/timeutils' ) type data struct { Time timeutils.

Parsing HTTP Query String in Go

TL;DR Code and examples can be found here: https://github.com/creack/httpreq HTTP Server Go provides a very easy way to create a http server: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 package main import ( 'fmt' 'log' 'net/http' ) func handler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, 'hello world\n') } func main() { log.Fatal(http.ListenAndServe(':8080', http.HandlerFunc(handler)))…

HTTP and Error management in Go

Go comes with a great standard library including net/http which allow a developer to create a reliable http server very easily. TL;DR Code and example can be found here: https://github.com/creack/ehttp Basic http server To provide context, let's take a look at a basic http server in Go: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 package main import ( 'fmt' 'log' 'net/http' ) func handler(w http.

Reverse Proxy in Go

TL;DR The final code can be found here: https://github.com/creack/goproxy Goal In this article, we are going to dive into the standard library's Reverse Proxy and see how to use it as a load balancer with persistent connections that doesn't lose any requests! Here is our example setup: Service One - version 1 running on http://localhost:9091/ and http://localhost:9092/ Reverse Proxy on…

Scope and Shadowing in Go

Variable shadowing can be confusing in Go, let's try to clear it up. Case of errors Without even maybe knowing it, you have been playing with shadowing with your errors. Consider the following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package main import ( 'io/ioutil' 'log' ) func main() { f, err := ioutil.TempFile('', '') if err !

Privileged Listen in Go

Introduction Go does not play well with Forks and User permission. The reason is because it is a threaded runtime and there is no mechanism for clean fork or clean setuid. To work around the fork issue, Go exposes syscall.ForkExec() which perform the fork (locked) but always perform an Exec() in the forked process, resulting in the calling one to disappear (overridden). The Issue.…

Selenium PhantomJS troubleshooting in Python

The problem After couple of minutes running, the machines crashes. Can't ssh, can't do anything. On an other machine, it works fine though… So what is going on? Troubleshoot After digging a bit, I figured that the machine working was running the pip package selenium==2.45.0 and the faulty one selenium==2.46.0. The python, node, phantomjs and the rest of the pip freeze are the same.…

Futures in Go

The Problem You have a function that returns an error, you want to run it in a goroutine. How to retrieve the error? The Solution I'll take the example of Docker utils package: (from master on 08/06/2014) https://github.com/docker/docker/blob/66c8f87e89ba0dd824cf640a159210fbbb8019ec/utils/utils.go#L40 func Go(f func() error) chan error { ch := make(chan error, 1) go func() { ch <- f() }() return…

How to properly contribute to a Go project

Golang as a very strict directory hierarchy on which the builder (and more generally the Go tools) rely on. I am often asked what is the proper way to contribute to a Go project. Use cases Contributing to a random Go project Working as a team on a &ldquo;central&rdquo; repository Contributing to a Go project with sub-repositories The problem The issue is that when you go get a project, it ends up…

Half a decade with Go - User side

Yesterday was Go 5th anniversary. For fun, I looked for trace of activity around that time. Today is the 5th anniversary of the oldest trace I found of myself playing with Go: http://go-lang.cat-v.org/irc-logs/old-go-nuts (11/11/2009) 23:56 -!- creack [n=creack@ip-67.net-80-236-112.lhaylesroses.rev.numericable.fr] has joined #go-nuts I will not repeat what has been said in the official Go blog,…

Release Go code (and others) via Docker using Makefile

In this article, I'll demonstrate how to leverage Makefile in order to release lightweight Docker image for production. Sample Application code 1 2 3 4 5 package main func main() { println('hello world') } Of course, do not forget to vendor your dependencies: godep save. In order to create a release image, we first need to build the binary. We will have 2 Dockerfiles. Main Dockerfile The main…

Benchmarking NSQ

In this article, I'll demonstrate: How to properly write tests that needs external services How to write a parallel benchmark NSQ performances Properly test services Self contained The idea is to write self-contained tests that do not leak one into an other. It is particularly useful when testing databases, http server or in our case, nsqd. For http tests, we use httptest.NewServer() which can be…

Play with NSQ in Go

In my previous article, we saw what was NSQ, now, let's try to play with it a bit more. Consumer As we saw previously, we can directly publish on NSQD via http using curl, so let's focus for now on the consumer part. NSQ provides a sample app that does the bridge between http and consumer: https://github.com/bitly/nsq/blob/master/apps/nsq_pubsub/nsq_pubsub.go As the goal is to use it in an…

First look at NSQ

I finally took the time to take a look at NSQ and it is pretty neat! What is NSQ? From their website (http://nsq.io/): NSQ is a realtime distributed messaging platform designed to operate at scale, handling billions of messages per day. Basically, it is a Queue the scales. It has been created by bitly and they use it in production, so it has proven its performances. Since, a lot of other companies…