Gorilla mux custom middleware

Just create a wrapper, it’s rather easy in Go: func HomeHandler(response http.ResponseWriter, request *http.Request) { fmt.Fprintf(response, “Hello home”) } func Middleware(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.Println(“middleware”, r.URL) h.ServeHTTP(w, r) }) } func main() { r := mux.NewRouter() r.HandleFunc(“https://stackoverflow.com/”, HomeHandler) http.Handle(“https://stackoverflow.com/”, Middleware(r)) }

Recursive locking in Go

I’m sorry to not answer your question directly: IMHO, the best way how to implement recursive locks in Go is to not implement them, but rather redesign your code to not need them in the first place. It’s probable, I think, that the desire for them indicates a wrong approach to some (unknown here) problem … Read more

Does Go have something like ThreadLocal from Java?

The Go runtime and standard libraries do not provide goroutine local storage or a goroutine identifier that can be used to implement goroutine local storage. The third party gls package implements goroutine local storage in an interesting way. Some find this package horrifying and others think it’s clever. The Go team recommends passing context explicitly … Read more

Is it best-practice to commit the `vendor` directory?

The dep tool’s FAQ answers this: Should I commit my vendor directory? It’s up to you: Pros It’s the only way to get truly reproducible builds, as it guards against upstream renames, deletes and commit history overwrites. You don’t need an extra dep ensure step to sync vendor/ with Gopkg.lock after most operations, such as … Read more