wide/util/ret.go

22 lines
386 B
Go

package util
import (
"encoding/json"
"net/http"
"github.com/golang/glog"
)
// RetJSON writes HTTP response with "Content-Type, application/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)
}