4 ms·
func must(err error) { if err != nil { panic(err) } } func (g *Gopher) DumpBinary(w io.Writer) (err error) { defer func() { err, _ = recove
by EdiX 13y ago
func must(err error) {
if err != nil { panic(err) }
}
func (g *Gopher) DumpBinary(w io.Writer) (err error) {
defer func() {
err, _ = recover().(error)
}
must(binary.Write(w, binary.LittleEndian, int32(len(g.Name))))
must(w.Write([]byte(g.Name)))
must(binary.Write(w, binary.LittleEndian, g.Age))
must(binary.Write(w, binary.LittleEndian, g.FurColor))
return
}
- inkel 13y agoThat won't work as it is with `w.Write`, as it returns two values, but yes, the idea is perfectly valid.