123456789101112131415161718192021222324252627 |
- package response
- import (
- "encoding/json"
- "net/http"
- )
- var responseCode = 200
- func JSON(w http.ResponseWriter, data interface{}) {
- 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)
- }
- func SetCode(code int) {
- responseCode = code
- }
|