initial commit

This commit is contained in:
maurice fletgen
2022-09-08 09:18:04 +02:00
commit 447b2fb51d
163 changed files with 47569 additions and 0 deletions

36
pkg/sys/requests.go Normal file
View 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)
}