search.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/web/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. "go-common/library/net/metadata"
  11. "go-common/library/xstr"
  12. )
  13. const (
  14. _searchVer = "v3"
  15. _searchPlatform = "web"
  16. _searchUpRecType = "up_rec"
  17. )
  18. // SearchAll search all data.
  19. func (d *Dao) SearchAll(c context.Context, mid int64, arg *model.SearchAllArg, buvid, ua, typ string) (res *model.Search, err error) {
  20. var (
  21. params = url.Values{}
  22. ip = metadata.String(c, metadata.RemoteIP)
  23. )
  24. params = setSearchParam(params, mid, model.SearchTypeAll, arg.Keyword, _searchPlatform, arg.FromSource, buvid, ip)
  25. params.Set("duration", strconv.Itoa(arg.Duration))
  26. params.Set("page", strconv.Itoa(arg.Pn))
  27. params.Set("tids", strconv.Itoa(arg.Rid))
  28. if typ == model.WxSearchType {
  29. params.Set("highlight", strconv.Itoa(arg.Highlight))
  30. for k, v := range model.SearchDefaultArg[model.WxSearchTypeAll] {
  31. params.Set(k, strconv.Itoa(v))
  32. }
  33. } else {
  34. for k, v := range model.SearchDefaultArg[model.SearchTypeAll] {
  35. params.Set(k, strconv.Itoa(v))
  36. }
  37. params.Set("single_column", strconv.Itoa(arg.SingleColumn))
  38. }
  39. var req *http.Request
  40. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  41. return
  42. }
  43. req.Header.Set("browser-info", ua)
  44. res = new(model.Search)
  45. if err = d.httpSearch.Do(c, req, &res); err != nil {
  46. log.Error("Search d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  47. return
  48. }
  49. if res.Code != ecode.OK.Code() {
  50. log.Error("Search d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  51. err = ecode.Int(res.Code)
  52. }
  53. return
  54. }
  55. // SearchVideo search season data.
  56. func (d *Dao) SearchVideo(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  57. var (
  58. params = url.Values{}
  59. ip = metadata.String(c, metadata.RemoteIP)
  60. )
  61. params = setSearchTypeParam(params, mid, model.SearchTypeVideo, buvid, ip, arg)
  62. params.Set("duration", strconv.Itoa(arg.Duration))
  63. params.Set("order", arg.Order)
  64. params.Set("from_source", arg.FromSource)
  65. params.Set("tids", strconv.FormatInt(arg.Rid, 10))
  66. params.Set("page", strconv.Itoa(arg.Pn))
  67. for k, v := range model.SearchDefaultArg[model.SearchTypeVideo] {
  68. params.Set(k, strconv.Itoa(v))
  69. }
  70. var req *http.Request
  71. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  72. return
  73. }
  74. req.Header.Set("browser-info", ua)
  75. res = new(model.SearchTypeRes)
  76. if err = d.httpSearch.Do(c, req, &res); err != nil {
  77. log.Error("SearchVideo d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  78. return
  79. }
  80. if res.Code != ecode.OK.Code() {
  81. log.Error("SearchVideo d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  82. err = ecode.Int(res.Code)
  83. }
  84. return
  85. }
  86. // SearchBangumi search bangumi data.
  87. func (d *Dao) SearchBangumi(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  88. var (
  89. params = url.Values{}
  90. ip = metadata.String(c, metadata.RemoteIP)
  91. )
  92. params = setSearchTypeParam(params, mid, model.SearchTypeBangumi, buvid, ip, arg)
  93. params.Set("duration", strconv.Itoa(arg.Duration))
  94. params.Set("order", arg.Order)
  95. params.Set("page", strconv.Itoa(arg.Pn))
  96. for k, v := range model.SearchDefaultArg[model.SearchTypeBangumi] {
  97. params.Set(k, strconv.Itoa(v))
  98. }
  99. var req *http.Request
  100. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  101. return
  102. }
  103. req.Header.Set("browser-info", ua)
  104. res = new(model.SearchTypeRes)
  105. if err = d.httpSearch.Do(c, req, &res); err != nil {
  106. log.Error("SearchBangumi d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  107. return
  108. }
  109. if res.Code != ecode.OK.Code() {
  110. log.Error("SearchBangumi d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  111. err = ecode.Int(res.Code)
  112. }
  113. return
  114. }
  115. // SearchPGC search pgc(movie) data.
  116. func (d *Dao) SearchPGC(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  117. var (
  118. params = url.Values{}
  119. ip = metadata.String(c, metadata.RemoteIP)
  120. )
  121. params = setSearchTypeParam(params, mid, model.SearchTypePGC, buvid, ip, arg)
  122. params.Set("page", strconv.Itoa(arg.Pn))
  123. for k, v := range model.SearchDefaultArg[model.SearchTypePGC] {
  124. params.Set(k, strconv.Itoa(v))
  125. }
  126. var req *http.Request
  127. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  128. return
  129. }
  130. req.Header.Set("browser-info", ua)
  131. res = new(model.SearchTypeRes)
  132. if err = d.httpSearch.Do(c, req, &res); err != nil {
  133. log.Error("SearchPGC d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  134. return
  135. }
  136. if res.Code != ecode.OK.Code() {
  137. log.Error("SearchPGC d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  138. err = ecode.Int(res.Code)
  139. }
  140. return
  141. }
  142. // SearchLive search live data.
  143. func (d *Dao) SearchLive(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  144. var (
  145. params = url.Values{}
  146. ip = metadata.String(c, metadata.RemoteIP)
  147. )
  148. params = setSearchTypeParam(params, mid, model.SearchTypeLive, buvid, ip, arg)
  149. params.Set("page", strconv.Itoa(arg.Pn))
  150. params.Set("order", arg.Order)
  151. for k, v := range model.SearchDefaultArg[model.SearchTypeLive] {
  152. params.Set(k, strconv.Itoa(v))
  153. }
  154. var req *http.Request
  155. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  156. return
  157. }
  158. req.Header.Set("browser-info", ua)
  159. res = new(model.SearchTypeRes)
  160. if err = d.httpSearch.Do(c, req, &res); err != nil {
  161. log.Error("SearchVideo d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  162. return
  163. }
  164. if res.Code != ecode.OK.Code() {
  165. log.Error("SearchVideo d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  166. err = ecode.Int(res.Code)
  167. }
  168. return
  169. }
  170. // SearchLiveRoom search live data.
  171. func (d *Dao) SearchLiveRoom(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  172. var (
  173. params = url.Values{}
  174. ip = metadata.String(c, metadata.RemoteIP)
  175. )
  176. params = setSearchTypeParam(params, mid, model.SearchTypeLiveRoom, buvid, ip, arg)
  177. params.Set("page", strconv.Itoa(arg.Pn))
  178. params.Set("order", arg.Order)
  179. for k, v := range model.SearchDefaultArg[model.SearchTypeLiveRoom] {
  180. params.Set(k, strconv.Itoa(v))
  181. }
  182. var req *http.Request
  183. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  184. return
  185. }
  186. req.Header.Set("browser-info", ua)
  187. res = new(model.SearchTypeRes)
  188. if err = d.httpSearch.Do(c, req, &res); err != nil {
  189. log.Error("SearchLiveRoom d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  190. return
  191. }
  192. if res.Code != ecode.OK.Code() {
  193. log.Error("SearchLiveRoom d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  194. err = ecode.Int(res.Code)
  195. }
  196. return
  197. }
  198. // SearchLiveUser search live user data.
  199. func (d *Dao) SearchLiveUser(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  200. var (
  201. params = url.Values{}
  202. ip = metadata.String(c, metadata.RemoteIP)
  203. )
  204. params = setSearchTypeParam(params, mid, model.SearchTypeLiveUser, buvid, ip, arg)
  205. params.Set("page", strconv.Itoa(arg.Pn))
  206. params.Set("order", arg.Order)
  207. for k, v := range model.SearchDefaultArg[model.SearchTypeLiveUser] {
  208. params.Set(k, strconv.Itoa(v))
  209. }
  210. var req *http.Request
  211. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  212. return
  213. }
  214. req.Header.Set("browser-info", ua)
  215. res = new(model.SearchTypeRes)
  216. if err = d.httpSearch.Do(c, req, &res); err != nil {
  217. log.Error("SearchVideo d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  218. return
  219. }
  220. if res.Code != ecode.OK.Code() {
  221. log.Error("SearchVideo d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  222. err = ecode.Int(res.Code)
  223. }
  224. return
  225. }
  226. // SearchArticle search article.
  227. func (d *Dao) SearchArticle(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  228. var (
  229. params = url.Values{}
  230. ip = metadata.String(c, metadata.RemoteIP)
  231. )
  232. params = setSearchTypeParam(params, mid, model.SearchTypeArticle, buvid, ip, arg)
  233. params.Set("category_id", strconv.FormatInt(arg.CategoryID, 10))
  234. params.Set("page", strconv.Itoa(arg.Pn))
  235. params.Set("order", arg.Order)
  236. for k, v := range model.SearchDefaultArg[model.SearchTypeArticle] {
  237. params.Set(k, strconv.Itoa(v))
  238. }
  239. var req *http.Request
  240. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  241. return
  242. }
  243. req.Header.Set("browser-info", ua)
  244. res = new(model.SearchTypeRes)
  245. if err = d.httpSearch.Do(c, req, &res); err != nil {
  246. log.Error("SearchArticle d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  247. return
  248. }
  249. if res.Code != ecode.OK.Code() {
  250. log.Error("SearchArticle d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  251. err = ecode.Int(res.Code)
  252. }
  253. return
  254. }
  255. // SearchSpecial search special data.
  256. func (d *Dao) SearchSpecial(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  257. var (
  258. params = url.Values{}
  259. ip = metadata.String(c, metadata.RemoteIP)
  260. )
  261. params = setSearchTypeParam(params, mid, model.SearchTypeSpecial, buvid, ip, arg)
  262. params.Set("page", strconv.Itoa(arg.Pn))
  263. params.Set("vp_num", strconv.Itoa(arg.VpNum))
  264. for k, v := range model.SearchDefaultArg[model.SearchTypeSpecial] {
  265. params.Set(k, strconv.Itoa(v))
  266. }
  267. var req *http.Request
  268. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  269. return
  270. }
  271. req.Header.Set("browser-info", ua)
  272. res = new(model.SearchTypeRes)
  273. if err = d.httpSearch.Do(c, req, &res); err != nil {
  274. log.Error("SearchSpecial d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  275. return
  276. }
  277. if res.Code != ecode.OK.Code() {
  278. log.Error("SearchSpecial d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  279. err = ecode.Int(res.Code)
  280. }
  281. return
  282. }
  283. // SearchTopic search topic data.
  284. func (d *Dao) SearchTopic(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  285. var (
  286. params = url.Values{}
  287. ip = metadata.String(c, metadata.RemoteIP)
  288. )
  289. params = setSearchTypeParam(params, mid, model.SearchTypeTopic, buvid, ip, arg)
  290. params.Set("page", strconv.Itoa(arg.Pn))
  291. for k, v := range model.SearchDefaultArg[model.SearchTypeTopic] {
  292. params.Set(k, strconv.Itoa(v))
  293. }
  294. if arg.Highlight > 0 {
  295. params.Set("highlight", strconv.Itoa(arg.Highlight))
  296. }
  297. var req *http.Request
  298. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  299. return
  300. }
  301. req.Header.Set("browser-info", ua)
  302. res = new(model.SearchTypeRes)
  303. if err = d.httpSearch.Do(c, req, &res); err != nil {
  304. log.Error("SearchVideo d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  305. return
  306. }
  307. if res.Code != ecode.OK.Code() {
  308. log.Error("SearchVideo d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  309. err = ecode.Int(res.Code)
  310. }
  311. return
  312. }
  313. // SearchUser search user data.
  314. func (d *Dao) SearchUser(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  315. var (
  316. params = url.Values{}
  317. ip = metadata.String(c, metadata.RemoteIP)
  318. )
  319. params = setSearchTypeParam(params, mid, model.SearchTypeUser, buvid, ip, arg)
  320. params.Set("page", strconv.Itoa(arg.Pn))
  321. params.Set("user_type", strconv.Itoa(arg.UserType))
  322. params.Set("bili_user_vl", strconv.Itoa(arg.BiliUserVl))
  323. params.Set("order_sort", strconv.Itoa(arg.OrderSort))
  324. params.Set("order", arg.Order)
  325. for k, v := range model.SearchDefaultArg[model.SearchTypeUser] {
  326. params.Set(k, strconv.Itoa(v))
  327. }
  328. var req *http.Request
  329. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  330. return
  331. }
  332. req.Header.Set("browser-info", ua)
  333. res = new(model.SearchTypeRes)
  334. if err = d.httpSearch.Do(c, req, &res); err != nil {
  335. log.Error("SearchUser d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  336. return
  337. }
  338. if res.Code != ecode.OK.Code() {
  339. log.Error("SearchUser d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  340. err = ecode.Int(res.Code)
  341. }
  342. return
  343. }
  344. // SearchPhoto search photo data.
  345. func (d *Dao) SearchPhoto(c context.Context, mid int64, arg *model.SearchTypeArg, buvid, ua string) (res *model.SearchTypeRes, err error) {
  346. var (
  347. params = url.Values{}
  348. ip = metadata.String(c, metadata.RemoteIP)
  349. )
  350. params = setSearchTypeParam(params, mid, model.SearchTypePhoto, buvid, ip, arg)
  351. params.Set("category_id", strconv.FormatInt(arg.CategoryID, 10))
  352. params.Set("page", strconv.Itoa(arg.Pn))
  353. params.Set("order", arg.Order)
  354. for k, v := range model.SearchDefaultArg[model.SearchTypePhoto] {
  355. params.Set(k, strconv.Itoa(v))
  356. }
  357. if arg.Highlight > 0 {
  358. params.Set("highlight", strconv.Itoa(arg.Highlight))
  359. }
  360. var req *http.Request
  361. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchURL, ip, params); err != nil {
  362. return
  363. }
  364. req.Header.Set("browser-info", ua)
  365. res = new(model.SearchTypeRes)
  366. if err = d.httpSearch.Do(c, req, &res); err != nil {
  367. log.Error("SearchPhoto d.httpSearch.Get(%s) error(%v)", d.searchURL, err)
  368. return
  369. }
  370. if res.Code != ecode.OK.Code() {
  371. log.Error("SearchPhoto d.httpSearch.Get(%s) code(%d) error", d.searchURL, res.Code)
  372. err = ecode.Int(res.Code)
  373. }
  374. return
  375. }
  376. // SearchRec search recommend data.
  377. func (d *Dao) SearchRec(c context.Context, mid int64, pn, ps int, keyword, fromSource, buvid, ua string) (res *model.SearchRec, err error) {
  378. var (
  379. params = url.Values{}
  380. ip = metadata.String(c, metadata.RemoteIP)
  381. )
  382. params = setSearchParam(params, mid, "", keyword, _searchPlatform, fromSource, buvid, ip)
  383. params.Set("page", strconv.Itoa(pn))
  384. params.Set("pagesize", strconv.Itoa(ps))
  385. var req *http.Request
  386. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchRecURL, ip, params); err != nil {
  387. return
  388. }
  389. req.Header.Set("browser-info", ua)
  390. res = new(model.SearchRec)
  391. if err = d.httpSearch.Do(c, req, &res); err != nil {
  392. log.Error("Search d.httpSearch.Get(%s) error(%v)", d.searchRecURL, err)
  393. return
  394. }
  395. if res.Code != ecode.OK.Code() {
  396. log.Error("Search d.httpSearch.Do(%s) code error(%d)", d.searchRecURL, res.Code)
  397. err = ecode.Int(res.Code)
  398. }
  399. return
  400. }
  401. // SearchDefault get search default word.
  402. func (d *Dao) SearchDefault(c context.Context, mid int64, fromSource, buvid, ua string) (data *model.SearchDefault, err error) {
  403. var (
  404. params = url.Values{}
  405. ip = metadata.String(c, metadata.RemoteIP)
  406. )
  407. params.Set("main_ver", _searchVer)
  408. params.Set("platform", _searchPlatform)
  409. params.Set("clientip", ip)
  410. params.Set("userid", strconv.FormatInt(mid, 10))
  411. params.Set("search_type", "default")
  412. params.Set("from_source", fromSource)
  413. params.Set("buvid", buvid)
  414. var req *http.Request
  415. if req, err = d.httpSearch.NewRequest(http.MethodGet, d.searchDefaultURL, ip, params); err != nil {
  416. return
  417. }
  418. req.Header.Set("browser-info", ua)
  419. var res struct {
  420. Code int `json:"code"`
  421. SeID string `json:"seid"`
  422. Tips string `json:"recommend_tips"`
  423. Result []struct {
  424. ID int64 `json:"id"`
  425. Name string `json:"name"`
  426. ShowName string `json:"show_name"`
  427. Type string `json:"type"`
  428. } `json:"result"`
  429. }
  430. if err = d.httpSearch.Do(c, req, &res); err != nil {
  431. log.Error("Search d.httpSearch.Get(%s) error(%v)", d.searchDefaultURL, err)
  432. return
  433. }
  434. if res.Code != ecode.OK.Code() {
  435. log.Error("Search d.httpSearch.Do(%s) code error(%d)", d.searchDefaultURL, res.Code)
  436. err = ecode.Int(res.Code)
  437. }
  438. if len(res.Result) == 0 {
  439. err = ecode.NothingFound
  440. return
  441. }
  442. data = &model.SearchDefault{}
  443. for _, v := range res.Result {
  444. data.Trackid = res.SeID
  445. data.ID = v.ID
  446. data.ShowName = v.ShowName
  447. data.Name = v.Name
  448. }
  449. return
  450. }
  451. // UpRecommend .
  452. func (d *Dao) UpRecommend(c context.Context, mid int64, arg *model.SearchUpRecArg, buvid string) (rs []*model.SearchUpRecRes, trackID string, err error) {
  453. var (
  454. params = url.Values{}
  455. ip = metadata.String(c, metadata.RemoteIP)
  456. )
  457. params.Set("userid", strconv.FormatInt(mid, 10))
  458. params.Set("service_area", arg.ServiceArea)
  459. params.Set("rec_type", _searchUpRecType)
  460. params.Set("platform", arg.Platform)
  461. params.Set("clientip", ip)
  462. params.Set("pagesize", strconv.Itoa(arg.Ps))
  463. params.Set("buvid", buvid)
  464. if arg.MobiApp != "" {
  465. params.Set("mobi_app", arg.MobiApp)
  466. }
  467. if arg.Device != "" {
  468. params.Set("device", arg.Device)
  469. }
  470. if arg.Build != 0 {
  471. params.Set("build", strconv.FormatInt(arg.Build, 10))
  472. }
  473. if arg.ContextID != 0 {
  474. params.Set("context_id", strconv.FormatInt(arg.ContextID, 10))
  475. }
  476. if len(arg.MainTids) > 0 {
  477. params.Set("main_tids", xstr.JoinInts(arg.MainTids))
  478. }
  479. if len(arg.SubTids) > 0 {
  480. params.Set("sub_tids", xstr.JoinInts(arg.SubTids))
  481. }
  482. var res struct {
  483. Code int `json:"code"`
  484. Trackid string `json:"trackid"`
  485. Data []*model.SearchUpRecRes `json:"data"`
  486. }
  487. if err = d.httpSearch.Get(c, d.searchUpRecURL, ip, params, &res); err != nil {
  488. log.Error("UpRecommend d.httpSearch.Get(%s) error(%v)", d.searchUpRecURL, err)
  489. return
  490. }
  491. if res.Code != ecode.OK.Code() {
  492. log.Error("UpRecommend d.httpSearch.Do(%s) code error(%d)", d.searchUpRecURL, res.Code)
  493. err = ecode.Int(res.Code)
  494. return
  495. }
  496. rs = res.Data
  497. trackID = res.Trackid
  498. return
  499. }
  500. // SearchEgg search egg.
  501. func (d *Dao) SearchEgg(c context.Context) (data []*model.SearchEgg, err error) {
  502. var (
  503. ip = metadata.String(c, metadata.RemoteIP)
  504. res struct {
  505. Code int `json:"code"`
  506. Data []*model.SearchEgg `json:"data"`
  507. }
  508. )
  509. if err = d.httpSearch.Get(c, d.searchEggURL, ip, url.Values{}, &res); err != nil {
  510. log.Error("SearchEgg d.httpSearch.Get(%s) error(%v)", d.searchEggURL, err)
  511. return
  512. }
  513. if res.Code != ecode.OK.Code() {
  514. log.Error("SearchEgg d.httpSearch.Do(%s) code error(%d)", d.searchEggURL, res.Code)
  515. err = ecode.Int(res.Code)
  516. return
  517. }
  518. data = res.Data
  519. return
  520. }
  521. func setSearchParam(param url.Values, mid int64, searchType, keyword, platform, fromSource, buvid, ip string) url.Values {
  522. param.Set("main_ver", _searchVer)
  523. if searchType != "" {
  524. param.Set("search_type", searchType)
  525. }
  526. param.Set("platform", platform)
  527. param.Set("keyword", keyword)
  528. param.Set("from_source", fromSource)
  529. param.Set("userid", strconv.FormatInt(mid, 10))
  530. param.Set("buvid", buvid)
  531. param.Set("clientip", ip)
  532. return param
  533. }
  534. func setSearchTypeParam(param url.Values, mid int64, searchType, buvid, ip string, arg *model.SearchTypeArg) url.Values {
  535. param.Set("main_ver", _searchVer)
  536. if searchType != "" {
  537. param.Set("search_type", searchType)
  538. }
  539. param.Set("platform", arg.Platform)
  540. param.Set("keyword", arg.Keyword)
  541. param.Set("from_source", arg.FromSource)
  542. param.Set("userid", strconv.FormatInt(mid, 10))
  543. param.Set("single_column", strconv.Itoa(arg.SingleColumn))
  544. param.Set("buvid", buvid)
  545. param.Set("clientip", ip)
  546. return param
  547. }