On Wednesday, 18 January 2017 06:07:00 UTC+1, Tomi Häsä wrote: > > What is the difference between Encoder and MarshalIndent? They both write > to a stream. When do you use Encoder? >
MarshallIndent is a shortcut that creates an encoder, calls encoder.Indent() and then calls encoder.Encode(): func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { var b bytes.Buffer enc := NewEncoder(&b) enc.Indent(prefix, indent) if err := enc.Encode(v); err != nil { return nil, err } return b.Bytes(), nil } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.