API: Encoder and Decoder options are chainable (#670)

Fixes #583
This commit is contained in:
Thomas Pelletier
2021-11-13 19:04:53 -05:00
committed by GitHub
parent 4dff8eaa4d
commit 64fe47161f
3 changed files with 11 additions and 6 deletions
+8 -4
View File
@@ -54,8 +54,9 @@ func NewEncoder(w io.Writer) *Encoder {
// inline tag:
//
// MyField `inline:"true"`
func (enc *Encoder) SetTablesInline(inline bool) {
func (enc *Encoder) SetTablesInline(inline bool) *Encoder {
enc.tablesInline = inline
return enc
}
// SetArraysMultiline forces the encoder to emit all arrays with one element per
@@ -64,20 +65,23 @@ func (enc *Encoder) SetTablesInline(inline bool) {
// This behavior can be controlled on an individual struct field basis with the multiline tag:
//
// MyField `multiline:"true"`
func (enc *Encoder) SetArraysMultiline(multiline bool) {
func (enc *Encoder) SetArraysMultiline(multiline bool) *Encoder {
enc.arraysMultiline = multiline
return enc
}
// SetIndentSymbol defines the string that should be used for indentation. The
// provided string is repeated for each indentation level. Defaults to two
// spaces.
func (enc *Encoder) SetIndentSymbol(s string) {
func (enc *Encoder) SetIndentSymbol(s string) *Encoder {
enc.indentSymbol = s
return enc
}
// SetIndentTables forces the encoder to intent tables and array tables.
func (enc *Encoder) SetIndentTables(indent bool) {
func (enc *Encoder) SetIndentTables(indent bool) *Encoder {
enc.indentTables = indent
return enc
}
// Encode writes a TOML representation of v to the stream.
+1 -1
View File
@@ -551,7 +551,7 @@ K = 42`,
type flagsSetters []struct {
name string
f func(enc *toml.Encoder, flag bool)
f func(enc *toml.Encoder, flag bool) *toml.Encoder
}
var allFlags = flagsSetters{
+2 -1
View File
@@ -48,8 +48,9 @@ func NewDecoder(r io.Reader) *Decoder {
// that could not be set on the target value. In that case, the decoder returns
// a StrictMissingError that can be used to retrieve the individual errors as
// well as generate a human readable description of the missing fields.
func (d *Decoder) SetStrict(strict bool) {
func (d *Decoder) SetStrict(strict bool) *Decoder {
d.strict = strict
return d
}
// Decode the whole content of r into v.