You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
360 B
17 lines
360 B
package jsend
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func Fail(w http.ResponseWriter, code int, data map[string]interface{}) {
|
|
jdata, err := json.Marshal(data)
|
|
if err != nil {
|
|
jdata = []byte("null")
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(code)
|
|
w.Write([]byte("{\"status\": \"fail\", \"data\": " + string(jdata) + "}"))
|
|
}
|