func toTomlValue(item interface{}, indent int) string {
	tab := strings.Repeat(" ", indent)
	switch value := item.(type) {
	case int:
		return tab + strconv.FormatInt(int64(value), 10)
	case int8:
		return tab + strconv.FormatInt(int64(value), 10)
	case int16:
		return tab + strconv.FormatInt(int64(value), 10)
	case int32:
		return tab + strconv.FormatInt(int64(value), 10)
	case int64:
		return tab + strconv.FormatInt(value, 10)
	case uint:
		return tab + strconv.FormatUint(uint64(value), 10)
	case uint8:
		return tab + strconv.FormatUint(uint64(value), 10)
	case uint16:
		return tab + strconv.FormatUint(uint64(value), 10)
	case uint32:
		return tab + strconv.FormatUint(uint64(value), 10)
	case uint64:
		return tab + strconv.FormatUint(value, 10)
	case float32:
		return tab + strconv.FormatFloat(float64(value), 'f', -1, 32)
	case float64:
		return tab + strconv.FormatFloat(value, 'f', -1, 64)
	case string:
		return tab + "\"" + encodeTomlString(value) + "\""
	case bool:
		if value {
			return "true"
		}
		return "false"
	case time.Time:
		return tab + value.Format(time.RFC3339)
	case []interface{}:
		result := tab + "[\n"
		for _, item := range value {
			result += toTomlValue(item, indent+2) + ",\n"
		}
		return result + tab + "]"
	case nil:
		return ""
	default:
		panic(fmt.Sprintf("unsupported value type %T: %v", value, value))
	}
}
Value print support function for ToString()
Outputs the TOML compliant string representation of a value
package toml
import (
	"fmt"
	"strconv"
	"strings"
	"time"
)
func encodeTomlString(value string) string {
	result := ""
	for _, rr := range value {
		intRr := uint16(rr)
		switch rr {
		case '\b':
			result += "\\b"
		case '\t':
			result += "\\t"
		case '\n':
			result += "\\n"
		case '\f':
			result += "\\f"
		case '\r':
			result += "\\r"
		case '"':
			result += "\\\""
		case '\\':
			result += "\\\\"
		default:
			if intRr < 0x001F {
				result += fmt.Sprintf("\\u%0.4X", intRr)
			} else {
				result += string(rr)
			}
		}
	}
	return result
}