bytes.Buffer の Write の error は見なくて良い
var buf bytes.Buffer if _, err := buf.Write(....); err != nil { ... } if _, err := buf.Write(....); err != nil { ... }
みたいなのが続くと err のチェックがだるいな〜みたなのを聞いて標準モジュール内での使われ方を見たりしたら、error のチェックをしないで
buf.Write(...) buf.Write(...)
のようなコードがあった。 なんでだろうとドキュメントを読んだらこうあってなるほどとなった。
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.