dynamic.go 731 B

1234567891011121314151617181920212223242526272829303132333435
  1. package web
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _opt = "1002"
  11. _platform = "web"
  12. )
  13. // PushAll broadcast push all
  14. func (d *Dao) PushAll(c context.Context, msg string, ip string) (err error) {
  15. var res struct {
  16. Code int `json:"code"`
  17. }
  18. params := url.Values{}
  19. params.Set("operation", _opt)
  20. params.Set("speed", strconv.Itoa(d.c.Rule.BroadFeed))
  21. params.Set("platform", _platform)
  22. params.Set("message", msg)
  23. if err = d.http.Post(c, d.broadcastURL, ip, params, &res); err != nil {
  24. log.Error("PushAll url(%s) error(%v)", d.broadcastURL+"?"+params.Encode(), err)
  25. return
  26. }
  27. if res.Code != ecode.OK.Code() {
  28. err = ecode.Int(res.Code)
  29. }
  30. return
  31. }