index.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package api
  2. import (
  3. requstform "Gwen/http/request/api"
  4. "Gwen/http/response"
  5. "Gwen/service"
  6. "github.com/gin-gonic/gin"
  7. "net/http"
  8. "time"
  9. )
  10. type Index struct {
  11. }
  12. // Index 首页
  13. // @Tags 首页
  14. // @Summary 首页
  15. // @Description 首页
  16. // @Accept json
  17. // @Produce json
  18. // @Success 200 {object} response.Response
  19. // @Failure 500 {object} response.Response
  20. // @Router / [get]
  21. func (i *Index) Index(c *gin.Context) {
  22. response.Success(
  23. c,
  24. "Hello Gwen",
  25. )
  26. }
  27. // Heartbeat 心跳
  28. // @Tags 首页
  29. // @Summary 心跳
  30. // @Description 心跳
  31. // @Accept json
  32. // @Produce json
  33. // @Success 200 {object} nil
  34. // @Failure 500 {object} response.Response
  35. // @Router /heartbeat [post]
  36. func (i *Index) Heartbeat(c *gin.Context) {
  37. info := &requstform.PeerInfoInHeartbeat{}
  38. err := c.ShouldBindJSON(info)
  39. if err != nil {
  40. c.JSON(http.StatusOK, gin.H{})
  41. return
  42. }
  43. if info.Uuid == "" {
  44. c.JSON(http.StatusOK, gin.H{})
  45. return
  46. }
  47. peer := service.AllService.PeerService.FindByUuid(info.Uuid)
  48. if peer == nil {
  49. c.JSON(http.StatusOK, gin.H{})
  50. return
  51. }
  52. peer.LastOnlineTime = time.Now().Unix()
  53. service.AllService.PeerService.Update(peer)
  54. c.JSON(http.StatusOK, gin.H{})
  55. }