dao.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package newcomer
  2. import (
  3. "context"
  4. grpc "go-common/app/interface/main/creative/api"
  5. "go-common/app/job/main/creative/conf"
  6. "go-common/library/database/sql"
  7. httpx "go-common/library/net/http/blademaster"
  8. )
  9. // Dao is search dao.
  10. type Dao struct {
  11. c *conf.Config
  12. //db
  13. db *sql.DB
  14. //grpc
  15. grpcClient grpc.CreativeClient
  16. // http
  17. httpClient *httpx.Client
  18. msgURI string
  19. }
  20. // New new a search dao.
  21. func New(c *conf.Config) (d *Dao) {
  22. d = &Dao{
  23. c: c,
  24. db: sql.NewMySQL(c.DB.Creative),
  25. httpClient: httpx.NewClient(c.HTTPClient.Slow),
  26. msgURI: c.Host.Message + "/api/notify/send.user.notify.do", //发送用户通知消息接口
  27. }
  28. var err error
  29. if d.grpcClient, err = grpc.NewClient(c.CreativeGRPClient); err != nil {
  30. panic(err)
  31. }
  32. return d
  33. }
  34. // CheckTaskState call grpc client.
  35. func (d *Dao) CheckTaskState(c context.Context, MID, TaskID int64) (*grpc.TaskReply, error) {
  36. return d.grpcClient.CheckTaskState(c, &grpc.TaskRequest{Mid: MID, TaskId: TaskID})
  37. }
  38. // Ping ping grpc.
  39. func (d *Dao) Ping(c context.Context) (err error) {
  40. d.grpcClient.Ping(c, nil)
  41. return
  42. }
  43. // Close close grpc.
  44. func (d *Dao) Close(c context.Context) (err error) {
  45. d.grpcClient.Close(c, nil)
  46. return
  47. }