request.go 702 B

123456789101112131415161718192021222324252627282930313233
  1. package wechat
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. sh "git.chuangxin1.com/myth/sacred/xhttp"
  6. )
  7. // getJSON GET response JSON
  8. func getJSON(uri string, v interface{}) (msg sh.Message, err error) {
  9. opt := sh.DefaultRequestOption()
  10. opt.AcceptEncodingGZIP()
  11. msg, err = sh.GetJSON(v, uri, opt)
  12. //fmt.Println(string(msg.Body), err)
  13. return
  14. }
  15. // postJSON POST json data and response JSON
  16. func postJSON(v interface{}, uri string, data interface{}) (msg sh.Message, err error) {
  17. bs, _ := json.Marshal(data)
  18. opt := sh.DefaultRequestOption()
  19. opt.AcceptEncodingGZIP()
  20. opt.SetContentTypeJSON()
  21. msg, err = sh.Post(uri, bytes.NewReader(bs), opt)
  22. if err != nil {
  23. return
  24. }
  25. err = msg.JSON(v)
  26. return
  27. }