Encode writes a TOML representation of the Go value to the underlying io.Writer. If the value given cannot be encoded to a valid TOML document, then an error is returned.

The mapping between Go values and TOML values should be precisely the same as for the Decode* functions. Similarly, the TextMarshaler interface is supported by encoding the resulting bytes as strings. (If you want to write arbitrary binary data then you will need to use something like base64 since TOML does not have any binary types.)

When encoding TOML hashes (i.e., Go maps or structs), keys without any sub-hashes are encoded first.

If a Go map is encoded, then its keys are sorted alphabetically for deterministic output. More control over this behavior may be provided if there is demand for it.

Encoding Go values without a corresponding TOML representation---like map types with non-string keys---will cause an error to be returned. Similarly for mixed arrays/slices, arrays/slices with nil elements, embedded non-struct types and nested slices containing maps or structs. (e.g., [][]map[string]string is not allowed but []map[string]string is OK and so is []map[string][]string.)

Encode is referenced in 0 repositories