Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
修正 Replace 小數點的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
YamiOdymel committed Dec 26, 2019
1 parent 371235c commit bf1cf49
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions shopeego.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"net/http"
"regexp"
"strings"
)

Expand Down Expand Up @@ -219,20 +220,19 @@ func (s *ShopeeClient) post(method string, in interface{}) ([]byte, error) {
}

//
replaceConcat := strings.Join(replaces, "|")
for _, v := range replaces {
body = []byte(strings.ReplaceAll(string(body), fmt.Sprintf(`"%s": 0`, v), fmt.Sprintf(`"%s": "0"`, v)))
body = []byte(strings.ReplaceAll(string(body), fmt.Sprintf(`"%s": ""`, v), fmt.Sprintf(`"%s": "0"`, v)))
}

var r = regexp.MustCompile(fmt.Sprintf(`"(%s)": ([^"].*?)(,|})`, replaceConcat))
body = []byte(r.ReplaceAllString(string(body), `"$1": "$2"$3`))

var errResp ResponseError
err = json.Unmarshal(body, &errResp)
if err != nil {
return []byte(``), err
}
_ = json.Unmarshal(body, &errResp)
if errResp.ErrorType != "" {
return []byte(``), errResp
}

return body, nil
}

Expand Down Expand Up @@ -973,6 +973,7 @@ func (s *ShopeeClient) GetOrderDetails(req *GetOrderDetailsRequest) (resp *GetOr
return
}
err = json.Unmarshal(b, &resp)
//panic(b)
if err != nil {
return
}
Expand Down

0 comments on commit bf1cf49

Please sign in to comment.