Case insensitive string search in golang

strings.EqualFold() can check if two strings are equal, while ignoring case. It even works with Unicode. See http://golang.org/pkg/strings/#EqualFold for more info. http://play.golang.org/p/KDdIi8c3Ar package main import ( “fmt” “strings” ) func main() { fmt.Println(strings.EqualFold(“HELLO”, “hello”)) fmt.Println(strings.EqualFold(“ÑOÑO”, “ñoño”)) } Both return true.

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)) }

Go Resizing Images

Read http://golang.org/pkg/image // you need the image package, and a format package for encoding/decoding import ( “bytes” “image” “image/jpeg” // if you don’t need to use jpeg.Encode, use this line instead // _ “image/jpeg” “github.com/nfnt/resize” ) // Decoding gives you an Image. // If you have an io.Reader already, you can give that to Decode …

Read more

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