Golang io/ioutil NopCloser

Whenever you need to return an io.ReadCloser, while making sure a Close() is available, you can use a NopCloser to build such a ReaderCloser. You can see one example in this fork of gorest, in util.go //Marshals the data in interface i into a byte slice, using the Marhaller/Unmarshaller specified in mime. //The Marhaller/Unmarshaller must … Read more

How to read multiple times from same io.Reader

io.Reader is treated like a stream. Because of this you cannot read it twice. Imagine an incoming TCP connection – you cannot rewind what’s coming in. But you can use the io.TeeReader to duplicate the stream: package main import ( “bytes” “io” “io/ioutil” “log” “strings” ) func main() { r := strings.NewReader(“some io.Reader stream to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)