func (e *Encoder) Encode(v interface{}) error {
	rv := reflect.ValueOf(v)
	for rv.Kind() == reflect.Ptr {
		if rv.IsNil() {
			return &marshalNilError{rv.Type()}
		}
		rv = rv.Elem()
	}
	buf := &tableBuf{typ: ast.TableTypeNormal}
	var err error
	switch rv.Kind() {
	case reflect.Struct:
		err = buf.structFields(e.cfg, rv)
	case reflect.Map:
		err = buf.mapFields(e.cfg, rv)
	default:
		err = &marshalTableError{rv.Type()}
	}
	if err != nil {
		return err
	}
	return buf.writeTo(e.w, "")
}
Encode writes the TOML of v to the stream.
See the documentation for Marshal for details about the conversion of Go values to TOML.
package toml
import (
	"bytes"
	"encoding"
	"fmt"
	"io"
	"reflect"
	"sort"
	"strconv"
	"time"
	"github.com/naoina/toml/ast"
)
const (
	tagOmitempty = "omitempty"
	tagSkip      = "-"
)
func (cfg *Config) Marshal(v interface{}) ([]byte, error) {
	buf := new(bytes.Buffer)
	err := cfg.NewEncoder(buf).Encode(v)
	return buf.Bytes(), err
}
type Encoder struct {
	w   io.Writer
	cfg *Config
}
func (cfg *Config) NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w, cfg}
}