bilibili-backup/app/interface/main/reply/dao/bigdata/bigdata.go

49 lines
1011 B
Go
Raw Permalink Normal View History

2019-04-22 10:59:20 +08:00
package bigdata
import (
"context"
"net/url"
"go-common/app/interface/main/reply/conf"
"go-common/library/ecode"
"go-common/library/log"
httpx "go-common/library/net/http/blademaster"
)
type result struct {
Code int `json:"code"`
}
// Dao bigdata dao
type Dao struct {
url string
topicURL string
httpClient *httpx.Client
}
// New return a bigdata dao
func New(c *conf.Config) *Dao {
d := &Dao{
httpClient: httpx.NewClient(c.HTTPClient),
url: c.Reply.BigdataURL,
topicURL: c.Reply.AiTopicURL,
}
return d
}
// Filter Filter
func (dao *Dao) Filter(c context.Context, msg string) (err error) {
params := url.Values{}
res := &result{}
params.Set("comment", msg)
if err = dao.httpClient.Post(c, dao.url, "", params, res); err != nil {
log.Error("Bigdata url(%s) error(%v)", dao.url+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("Bigdata url(%s) error(%v)", dao.url+"?"+params.Encode(), res.Code)
err = ecode.ReplyDeniedAsGarbage
}
return
}