wide/util/ret.go

22 lines
349 B
Go

package util
import (
"encoding/json"
"net/http"
"github.com/golang/glog"
)
// HTTP 返回 JSON 统一处理.
func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
w.Header().Set("Content-Type", "application/json")
data, err := json.Marshal(res)
if err != nil {
glog.Error(err)
return
}
w.Write(data)
}