123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package dao
- import (
- "context"
- "net/url"
- "strconv"
- "go-common/app/interface/main/web/model"
- "go-common/library/ecode"
- "go-common/library/log"
- "go-common/library/net/metadata"
- )
- // OnlineCount get online count
- func (d *Dao) OnlineCount(c context.Context) (data *model.OnlineCount, err error) {
- var (
- params = url.Values{}
- ip = metadata.String(c, metadata.RemoteIP)
- )
- var res struct {
- Code int `json:"code"`
- Data *model.OnlineCount `json:"data"`
- }
- if err = d.httpR.Get(c, d.onlineURL, ip, params, &res); err != nil {
- log.Error(" d.httpW.Get.Get(%s) error(%v)", d.onlineURL, err)
- return
- }
- if res.Code != ecode.OK.Code() {
- log.Error("d.httpW.Get(%s) code error(%d)", d.onlineURL, res.Code)
- err = ecode.Int(res.Code)
- return
- }
- data = res.Data
- return
- }
- // LiveOnlineCount get live online count
- func (d *Dao) LiveOnlineCount(c context.Context) (data *model.LiveOnlineCount, err error) {
- var (
- params = url.Values{}
- ip = metadata.String(c, metadata.RemoteIP)
- )
- var res struct {
- Code int `json:"code"`
- Data *model.LiveOnlineCount `json:"data"`
- }
- if err = d.httpR.Get(c, d.liveOnlineURL, ip, params, &res); err != nil {
- log.Error(" d.httpW.Get.Get(%s) error(%v)", d.liveOnlineURL, err)
- return
- }
- if res.Code != ecode.OK.Code() {
- log.Error("d.httpW.Get(%s) code error(%d)", d.liveOnlineURL, res.Code)
- err = ecode.Int(res.Code)
- return
- }
- data = res.Data
- return
- }
- // OnlineList get online list
- func (d *Dao) OnlineList(c context.Context, num int64) (data []*model.OnlineAid, err error) {
- var (
- params = url.Values{}
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params.Set("num", strconv.FormatInt(num, 10))
- var res struct {
- Code int `json:"code"`
- Data []*model.OnlineAid `json:"data"`
- }
- if err = d.httpR.Get(c, d.onlineListURL, ip, params, &res); err != nil {
- log.Error(" d.httpR.Get.Get(%s) error(%v)", d.onlineListURL, err)
- return
- }
- if res.Code != ecode.OK.Code() {
- log.Error("d.httpR.Get(%s) code error(%d)", d.onlineListURL, res.Code)
- return
- }
- data = res.Data
- return
- }
|