func (m Marshaller) Marshal(v interface{}) (string, error) {
	bytes, err := m(v)
	if err != nil {
		return "", err
	}
	return string(bytes), nil
}
Marshal marshals the given value
package cmdutil
import (
	"encoding/json"
	"fmt"
	"sort"
	"strconv"
	"strings"
	"github.com/ghodss/yaml"
)
const (
	JSON = "json"
	YAML = "yaml"
	TEXT = "text"
)
type Marshaller func(interface{}) ([]byte, error)
type YamlMarshaler interface {
	MarshalYAML() ([]byte, error)
}
type TextMarshaler interface {
	MarshalTEXT() ([]byte, error)
}
func NewMarshaller(format string) (Marshaller, error) {
	switch format {
	case JSON:
		return Marshaller(func(v interface{}) ([]byte, error) {
			return json.MarshalIndent(v, "", "  ")
		}), nil
	case YAML:
		return Marshaller(func(v interface{}) ([]byte, error) {
			switch t := v.(type) {
			case YamlMarshaler:
				return t.MarshalYAML()
			default:
				return yaml.Marshal(v)
			}
		}), nil
	case TEXT:
		return Marshaller(toText), nil
	default:
		return nil, fmt.Errorf("the %v format is not supported. Supported formats are 'json' or 'yaml'", format)
	}
}