acc.go 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _accErrWasFormal = -659
  11. )
  12. // BeFormal be formal member.
  13. func (d *Dao) BeFormal(c context.Context, mid int64, cookie, ip string) (err error) {
  14. params := url.Values{}
  15. params.Set("Cookie", cookie)
  16. params.Set("mid", strconv.FormatInt(mid, 10))
  17. // request
  18. req, err := d.httpClient.NewRequest("POST", d.beFormalURI, ip, params)
  19. if err != nil {
  20. log.Error("account beformal uri(%s) error(%v)", d.beFormalURI+params.Encode(), err)
  21. return
  22. }
  23. req.Header.Set("Cookie", cookie)
  24. var res struct {
  25. Code int `json:"code"`
  26. }
  27. if err = d.httpClient.Do(c, req, &res); err != nil {
  28. return
  29. }
  30. if res.Code != 0 {
  31. if res.Code == _accErrWasFormal {
  32. return
  33. }
  34. err = ecode.Int(res.Code)
  35. log.Error("account beformal uri(%s) error(%v)", d.beFormalURI+params.Encode(), err)
  36. }
  37. return
  38. }