12345678910111213141516171819202122232425262728293031323334 |
- package response
- import (
- "encoding/json"
- "net/http"
- )
- var responseCode = 200
- var responseWriter *http.ResponseWriter
- //JSON :response json
- func JSON(data interface{}) {
- w := *responseWriter
- js, err := json.Marshal(data)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(responseCode)
- w.Write(js)
- }
- //SetCode :informa o código de resposta
- func SetCode(code int) {
- responseCode = code
- }
- func SetResponseWriter(w http.ResponseWriter) {
- responseWriter = &w
- }
|