refactor
This commit is contained in:
17
client/httputil/response.go
Normal file
17
client/httputil/response.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, status int, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
jsonBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(jsonBytes)
|
||||
}
|
||||
Reference in New Issue
Block a user