func jsonHandler(ctx ol.Context, rv interface{}) http.Handler {
	var err error
	var b []byte
	if b, err = json.Marshal(rv); err != nil {
		return Error(ctx, err)
	}
	status := http.StatusOK
	if v, ok := rv.(HTTPStatus); ok {
		status = v.Status()
	}
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		SetHeader(w)
		q := r.URL.Query()
		if cb := q.Get("callback"); cb != "" {
			w.Header().Set("Content-Type", HttpJavaScript)
			if status != http.StatusOK {
				w.WriteHeader(status)
			}
			fmt.Fprintf(w, "%s(%s)", cb, string(b))
		} else {
			w.Header().Set("Content-Type", HttpJson)
			if status != http.StatusOK {
				w.WriteHeader(status)
			}
			w.Write(b)
		}
	})
}
response json directly.
package http
import (
	"encoding/json"
	"fmt"
	ol "github.com/ossrs/go-oryx-lib/logger"
	"net/http"
	"os"
	"strconv"
	"strings"
)
const (
	HttpJson       = "application/json"
	HttpJavaScript = "application/javascript"
)
var Server = "Oryx"
type SystemError int
func (v SystemError) Error() string {
	return fmt.Sprintf("System error=%d", int(v))
}
type SystemComplexError struct {
	Code SystemError `json:"code"`
	Message string `json:"data"`
}
func (v SystemComplexError) Error() string {
	return fmt.Sprintf("%v, %v", v.Code.Error(), v.Message)
}
type AppError interface {
	Code() int
	error
}
type HTTPStatus interface {
	Status() int
}
func Error(ctx ol.Context, err error) http.Handler {
	if v, ok := err.(SystemComplexError); ok {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			jsonHandler(ctx, FilterCplxSystemError(ctx, w, r, v)).ServeHTTP(w, r)
		})
	}
	if v, ok := err.(SystemError); ok {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			jsonHandler(ctx, FilterSystemError(ctx, w, r, v)).ServeHTTP(w, r)
		})
	}
	if v, ok := err.(AppError); ok {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			jsonHandler(ctx, FilterAppError(ctx, w, r, v)).ServeHTTP(w, r)
		})
	}
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		SetHeader(w)
		w.Header().Set("Content-Type", HttpJson)
		status := http.StatusInternalServerError
		if v, ok := err.(HTTPStatus); ok {
			status = v.Status()
		}
		http.Error(w, FilterError(ctx, w, r, err), status)
	})
}
func CplxError(ctx ol.Context, code SystemError, message string) http.Handler {
	return Error(ctx, SystemComplexError{code, message})
}
func Data(ctx ol.Context, v interface{}) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		jsonHandler(ctx, FilterData(ctx, w, r, v)).ServeHTTP(w, r)
	})
}
func SetHeader(w http.ResponseWriter) {
	w.Header().Set("Server", Server)
}