github.com/pavlo67/common@v0.5.3/common/server_http/responses.go (about) 1 package server_http 2 3 const ErrorKey = "error_key" 4 5 type ResponseFinished struct { 6 Response Response 7 Error error 8 } 9 10 type Response struct { 11 Status int 12 Data []byte 13 MIMEType string 14 FileName string 15 } 16 17 //func ResponseRESTError(identity,status int, key DeviceKey, err error) (Response, error) { 18 // if err == nil { 19 // err = fmt.Errorf("unknown error with status %d", status) 20 // } 21 // if status == 0 || status == http.StatusOK { 22 // status = http.StatusInternalServerError 23 // } 24 // 25 // data := common.Map{"error": key} 26 // if os.Getenv("ENV") != "production" { 27 // data["details"] = err.Error() 28 // } 29 // 30 // dataBytes, _ := json.Marshal(data) 31 // 32 // return Response{Status: status, data: dataBytes}, err 33 //} 34 // 35 //func ResponseRESTOk(identity,data interface{}) (Response, error) { 36 // if data == nil { 37 // return Response{Status: http.StatusOK}, nil 38 // } 39 // 40 // jsonBytes, err := json.Marshal(data) 41 // if err != nil { 42 // return Response{Status: http.StatusInternalServerError}, errors.Wrapf(err, "can't marshal pbxm (%#v)", data) 43 // } 44 // 45 // return Response{Status: http.StatusOK, data: jsonBytes}, nil 46 //}