func (c CBOR) Marshal(value interface{}) ([]byte, error) {
	return cbor.Marshal(value)
}
Marshal the value to encoded YAML.
package cli
import (
	"encoding/json"
	"fmt"
	"reflect"
	"strings"
	"github.com/amzn/ion-go/ion"
	"github.com/fxamacker/cbor/v2"
	"github.com/shamaton/msgpack"
	"gopkg.in/yaml.v2"
)
type ContentType interface {
	Detect(contentType string) bool
	Marshal(value interface{}) ([]byte, error)
	Unmarshal(data []byte, value interface{}) error
}
type contentTypeEntry struct {
	name string
	q    float32
	ct   ContentType
}
var contentTypes []contentTypeEntry = []contentTypeEntry{}
func AddContentType(name string, q float32, ct ContentType) {
	contentTypes = append(contentTypes, contentTypeEntry{
		name: name,
		q:    q,
		ct:   ct,
	})
}
func buildAcceptHeader() string {
	accept := []string{}
	for _, entry := range contentTypes {
		accept = append(accept, fmt.Sprintf("%s;q=%.3g", entry.name, entry.q))
	}
	accept = append(accept, "*/*")
	return strings.Join(accept, ",")
}
func Marshal(contentType string, value interface{}) ([]byte, error) {
	for _, entry := range contentTypes {
		if entry.ct.Detect(contentType) {
			return entry.ct.Marshal(value)
		}
	}
	return nil, fmt.Errorf("cannot marshal %s", contentType)
}
func Unmarshal(contentType string, data []byte, value interface{}) error {
	for _, entry := range contentTypes {
		if entry.ct.Detect(contentType) {
			LogDebug("Unmarshalling from %s", entry.name)
			return entry.ct.Unmarshal(data, value)
		}
	}
	return fmt.Errorf("cannot unmarshal %s", contentType)
}
type stringer interface {
	String() string
}
type Text struct{}
func (t Text) Detect(contentType string) bool {
	if strings.HasPrefix(contentType, "text/") {
		return true
	}
	known := []string{
		"application/javascript",
	}
	for _, ct := range known {
		if strings.Contains(contentType, ct) {
			return true
		}
	}
	return false
}
func (t Text) Marshal(value interface{}) ([]byte, error) {
	if s, ok := value.(string); ok {
		return []byte(s), nil
	}
	if s, ok := value.(stringer); ok {
		return []byte(s.String()), nil
	}
	return nil, fmt.Errorf("cannot convert to string: %v", value)
}
func (t Text) Unmarshal(data []byte, value interface{}) error {
	v := reflect.ValueOf(value)
	if v.Kind() != reflect.Ptr {
		return fmt.Errorf("value must be pointer but found %s", v.Kind())
	}
	if !v.Elem().CanSet() {
		return fmt.Errorf("interface value cannot be set")
	}
	v.Elem().Set(reflect.ValueOf(string(data)))
	return nil
}
type JSON struct{}
func (j JSON) Detect(contentType string) bool {
	first := strings.Split(contentType, ";")[0]
	if first == "application/json" || strings.HasSuffix(first, "+json") {
		return true
	}
	return false
}
func (j JSON) Marshal(value interface{}) ([]byte, error) {
	return json.Marshal(value)
}
func (j JSON) Unmarshal(data []byte, value interface{}) error {
	return json.Unmarshal(data, value)
}
type YAML struct{}
func (y YAML) Detect(contentType string) bool {
	first := strings.Split(contentType, ";")[0]
	if first == "application/yaml" || first == "application/x-yaml" || strings.HasSuffix(first, "+yaml") {
		return true
	}
	return false
}
func (y YAML) Marshal(value interface{}) ([]byte, error) {
	return yaml.Marshal(value)
}
func (y YAML) Unmarshal(data []byte, value interface{}) error {
	return yaml.Unmarshal(data, value)
}
type CBOR struct{}
func (c CBOR) Detect(contentType string) bool {
	first := strings.Split(contentType, ";")[0]
	if first == "application/cbor" || strings.HasSuffix(first, "+cbor") {
		return true
	}
	return false
}