initial commit
This commit is contained in:
36
pkg/sys/requests.go
Normal file
36
pkg/sys/requests.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SuccessJsonResponse(w http.ResponseWriter, data interface{}) {
|
||||
raw, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
// @TODO generic error
|
||||
http.Error(w, `{"type":"error", "code":"request_data_could_prepared_for_reply"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(raw)
|
||||
}
|
||||
|
||||
func ErrorJsonResponse(w http.ResponseWriter, code string, err error) {
|
||||
raw, err := json.Marshal(struct {
|
||||
Type string
|
||||
Code string
|
||||
Msg string
|
||||
}{
|
||||
Type: "error",
|
||||
Code: code,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
if err != nil {
|
||||
// @TODO generic error
|
||||
http.Error(w, `{"type":"error", "code":"request_data_could_prepared_for_reply"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(raw)
|
||||
}
|
||||
Reference in New Issue
Block a user