1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 07:42:27 +08:00

feat: add ParseResponse func in netutil/request.go

This commit is contained in:
dudaodong
2021-12-17 17:23:18 +08:00
parent 26b59dd56b
commit e87f3b70f0
2 changed files with 35 additions and 0 deletions

View File

@@ -12,6 +12,8 @@
package netutil
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sort"
@@ -43,6 +45,15 @@ func HttpPatch(url string, params ...interface{}) (*http.Response, error) {
return request(http.MethodPatch, url, params...)
}
// ParseResponse convert the http response to interface{} obj
func ParseResponse(resp *http.Response, obj interface{}) error {
if resp == nil {
return errors.New("InvalidResp")
}
defer resp.Body.Close()
return json.NewDecoder(resp.Body).Decode(obj)
}
// ConvertMapToQueryString convert map to sorted url query string
func ConvertMapToQueryString(param map[string]interface{}) string {
if param == nil {