Skip to content

Commit

Permalink
优化日志
Browse files Browse the repository at this point in the history
  • Loading branch information
name committed Dec 26, 2021
1 parent 5cc3d91 commit 08a4ba7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions utils/httputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"net/http"
"strconv"
)

const RSAPublicKey = "-----BEGIN RSA Public Key-----\n" +
Expand Down Expand Up @@ -51,7 +52,7 @@ func PostData(uri string, v interface{}) (error, map[string]interface{}) {
text := string(bytesData)
if has && d == text {
log.Println("数据已经提交过,避免重复提交, uri:", uri)
return nil, nil
//return nil, nil
}
reader := bytes.NewReader(bytesData)
err, resp := request("POST", uri, reader)
Expand Down Expand Up @@ -81,14 +82,24 @@ func request(method, uri string, body io.Reader) (error, map[string]interface{})
log.Println(err.Error())
return err, map[string]interface{}{}
}

respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err.Error())
return err, map[string]interface{}{}
}

if resp.StatusCode != 200 {
return errors.New(resp.Status), map[string]interface{}{
"code": strconv.FormatInt(int64(int(resp.StatusCode)), 10),
"msg": string(respBytes),
}
}

//byte数组直接转成string,优化内存
res := map[string]interface{}{}
json.Unmarshal(respBytes, &res)
err = json.Unmarshal(respBytes, &res)
log.Println(err)

return nil, res
}

0 comments on commit 08a4ba7

Please sign in to comment.