From 7bffd9a638a1888f22f68a8b191bc9e4b54e3e99 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 12 Aug 2023 20:31:39 +0800 Subject: [PATCH] 1 --- sysutils.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sysutils.go b/sysutils.go index c08832a..17eb523 100644 --- a/sysutils.go +++ b/sysutils.go @@ -6,8 +6,9 @@ import ( "fmt" "net/http" "time" - //"io/ioutil" + "io/ioutil" "reflect" + "encoding/json" ) func GetDaySeconds(seconds int64, timeZone int64) int64 { @@ -54,26 +55,24 @@ func ResponseOk(w* http.ResponseWriter) { } func ResponseErr(w* http.ResponseWriter, errCode int32, errMsg string) { - /*respObj := NewMxoObject() - respObj.SetXValue("errcode", NewXInt32(errCode)) - respObj.SetXValue("errmsg", NewXString(errMsg)) - Response(w, respObj.ToJsonStr())*/ + rspObj := map[string]interface{}{} + rspObj["errcode"] = errCode + rspObj["errmsg"] = errMsg + jsonObj, _ := json.Marshal(rspObj) + Response(w, string(jsonObj)) } func ResponseInt32Ok(w* http.ResponseWriter, key string, val int32) { (*w).Write([]byte(fmt.Sprintf(`{"errcode":0, "errmsg":"", "%s":%d}`, key, val))) } -/* -func GetPostBody(r *http.Request) *XValue { +func GetPostBody(r *http.Request) string { body, err := ioutil.ReadAll(r.Body) if err != nil { - return NewXString("") + return "" } - v := NewXString(string(body)) - return v + return string(body) } -*/ func GetRequestRemoteAddr(r *http.Request) string { remoteAddr := r.RemoteAddr