search.go 941 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package controllers
  2. import (
  3. "hongze/hongze_cygx/models"
  4. "hongze/hongze_cygx/services"
  5. )
  6. type SearchController struct {
  7. BaseCommonController
  8. }
  9. // @Title 搜索接口
  10. // @Description 搜索接口
  11. // @Param KeyWord query string true "搜索关键词"
  12. // @Success 200 {object} models.HomeListResp
  13. // @router /list [get]
  14. func (this *SearchController) SearchList() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. keyWord := this.GetString("KeyWord")
  21. if keyWord == "" {
  22. br.Msg = "请输入搜索词"
  23. br.ErrMsg = "请输入搜索词"
  24. return
  25. }
  26. pageSize := 20
  27. result, err := services.SearchByKeyWord(keyWord, pageSize)
  28. if err != nil {
  29. br.Msg = "检索失败"
  30. br.ErrMsg = "检索失败,Err:" + err.Error()
  31. return
  32. }
  33. br.Ret = 200
  34. br.Success = true
  35. br.Msg = "获取成功"
  36. br.Data = result
  37. }
  38. //https://blog.csdn.net/my_miuye/article/details/110496025