func (c *Context) YAMLWithCodeMsg(v interface{}, code int, msg string) {
	c.YAMLResult(c.ObjWithCodeMsg(v, code, msg))
}
YAMLWithCodeMsg output YAML data to client
v data
code is message code
msg is string message
package bast
import (
	"bufio"
	"encoding/json"
	"encoding/xml"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"math"
	"net"
	"net/http"
	"net/url"
	"path/filepath"
	"reflect"
	"strconv"
	"strings"
	"github.com/axfor/bast/conf"
	"github.com/axfor/bast/guid"
	"github.com/axfor/bast/lang"
	"github.com/axfor/bast/logs"
	"github.com/axfor/bast/session/engine"
	"github.com/axfor/bast/validate"
	"github.com/julienschmidt/httprouter"
	"gopkg.in/yaml.v2"
)
const (
	SerError                = 0        
	SerOK                   = 1        
	SerDBError              = -10000   
	SerNoDataError          = -20000   
	SerSignOutError         = -30000   
	SerUserNotExistError    = -40000   
	SerInvalidParamError    = -50000   
	SerInvalidUserAuthorize = -60000   
	SerExist                = -70000   
	SerNotExist             = -80000   
	SerTry                  = -99999   
	SerMustFailed           = -111111  
	SerFailed               = -222222  
	SerAuthorizationFailed  = -888888  
	KindAcceptJSON          = 0        
	KindAcceptXML           = 1        
	KindAcceptYAML          = 2        
)
var valid = validate.Validator{}
type Context struct {
	In *http.Request
	Accept string
	KindAccept int
	Out http.ResponseWriter
	Params httprouter.Params
	isParseForm bool
	NeedAuthorization bool
	IsAuthorization bool
	Session engine.Store
	Router *Pattern
}
type Message struct {
	XMLName xml.Name `xml:"msg" json:"-" yaml:"-"`
	Code    int      `json:"code" xml:"code" yaml:"code"`
	Msg     string   `json:"msg" xml:"msg" yaml:"msg"`
}
type MessageDetail struct {
	XMLName xml.Name `xml:"msg" json:"-" yaml:"-"`
	Code    int      `json:"code" xml:"code" yaml:"code"`
	Msg     string   `json:"msg" xml:"msg" yaml:"msg"`
	Detail  string   `json:"detail" xml:"detail" yaml:"detail"`
}
type Datum struct {
	Message `yaml:",inline"`
	XMLName xml.Name    `xml:"data"  json:"-" yaml:"-"`
	Data    interface{} `json:"data" xml:"data>data" yaml:"data"`
}
type Pagination struct {
	Message `yaml:",inline"`
	XMLName xml.Name    `xml:"page" json:"-" yaml:"-"`
	Data    interface{} `json:"data" xml:"data>data" yaml:"data"`
	Page    int         `json:"page" xml:"page" yaml:"page"`
	Total   int         `json:"total" xml:"total" yaml:"total"`
}
type InvalidPagination struct {
	Pagination `yaml:",inline"`
	XMLName    xml.Name `xml:"page" json:"-" yaml:"-"`
	Invalid    bool     `json:"invalid" xml:"invalid" yaml:"invalid"`
	Fix        bool     `json:"fix" xml:"fix" yaml:"fix"`
}
func (c *Context) Data(v interface{}) {
	c.DataWithCodeMsg(v, SerOK, "")
}
func (c *Context) DataWithCode(v interface{}, code int) {
	c.DataWithCodeMsg(v, code, "")
}
func (c *Context) DataWithMsg(v interface{}, msg string) {
	c.DataWithCodeMsg(v, SerOK, msg)
}
func (c *Context) DataWithCodeMsg(v interface{}, code int, msg string) {
	c.DataResult(c.ObjWithCodeMsg(v, code, msg))
}
func (c *Context) DataResult(v interface{}) {
	switch c.KindAccept {
	case KindAcceptJSON:
		c.JSONResult(v)
		break
	case KindAcceptXML:
		c.XMLResult(v)
		break
	case KindAcceptYAML:
		c.YAMLResult(v)
		break
	}
}
func (c *Context) Page(v interface{}, page, total int) {
	c.PageWithCodeMsg(v, page, total, SerOK, "")
}
func (c *Context) PageWithCode(v interface{}, page, total, code int) {
	c.PageWithCodeMsg(v, page, total, code, "")
}
func (c *Context) PageWithCodeMsg(v interface{}, page, total, code int, msg string) {
	c.DataResult(c.ObjWithPageCodeMsg(v, page, total, code, msg))
}
func (c *Context) JSON(v interface{}) {
	c.JSONWithCodeMsg(v, SerOK, "")
}
func (c *Context) JSONWithCode(v interface{}, code int) {
	c.JSONWithCodeMsg(v, code, "")
}
func (c *Context) JSONWithMsg(v interface{}, msg string) {
	c.JSONWithCodeMsg(v, SerOK, msg)
}
func (c *Context) JSONWithCodeMsg(v interface{}, code int, msg string) {
	c.JSONResult(c.ObjWithCodeMsg(v, code, msg))
}
func (c *Context) JSONWithPage(v interface{}, page, total int) {
	c.JSONWithPageCodeMsg(v, page, total, SerOK, "")
}
func (c *Context) JSONWithPageCode(v interface{}, page, total, code int) {
	c.JSONWithPageCodeMsg(v, page, total, code, "")
}
func (c *Context) JSONWithPageCodeMsg(v interface{}, page, total, code int, msg string) {
	c.JSONResult(c.ObjWithPageCodeMsg(v, page, total, code, msg))
}
func (c *Context) JSONResult(v interface{}) {
	data, err := json.Marshal(v)
	if err != nil {
		logs.Errors("JSONResult error", err)
		c.StatusCode(http.StatusInternalServerError)
		return
	}
	c.Out.Header().Set("Content-Type", "application/json")
	c.Out.Write(data)
	data = nil
}
func (c *Context) XML(v interface{}) {
	c.XMLWithCodeMsg(v, SerOK, "")
}
func (c *Context) XMLWithCode(v interface{}, code int) {
	c.XMLWithCodeMsg(v, code, "")
}
func (c *Context) XMLWithMsg(v interface{}, msg string) {
	c.XMLWithCodeMsg(v, SerOK, msg)
}
func (c *Context) XMLWithCodeMsg(v interface{}, code int, msg string) {
	c.XMLResult(c.ObjWithCodeMsg(v, code, msg))
}
func (c *Context) XMLWithPage(v interface{}, page, total int) {
	c.XMLWithPageCodeMsg(v, page, total, SerOK, "")
}
func (c *Context) XMLWithPageCode(v interface{}, page, total, code int) {
	c.XMLWithPageCodeMsg(v, page, total, code, "")
}
func (c *Context) XMLWithPageCodeMsg(v interface{}, page, total, code int, msg string) {
	c.XMLResult(c.ObjWithPageCodeMsg(v, page, total, code, msg))
}
func (c *Context) XMLResult(v interface{}) {
	data, err := xml.Marshal(v)
	if err != nil {
		logs.Errors("XMLResult error", err)
		c.StatusCode(http.StatusInternalServerError)
		return
	}
	c.Out.Header().Set("Content-Type", "application/xml")
	c.Out.Write(data)
	data = nil
}
func (c *Context) YAML(v interface{}) {
	c.YAMLWithCodeMsg(v, SerOK, "")
}
func (c *Context) YAMLWithCode(v interface{}, code int) {
	c.YAMLWithCodeMsg(v, code, "")
}
func (c *Context) YAMLWithMsg(v interface{}, msg string) {
	c.YAMLWithCodeMsg(v, SerOK, msg)
}