peer.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. "github.com/gin-gonic/gin/binding"
  8. "net/http"
  9. )
  10. type Peer struct {
  11. }
  12. // SysInfo
  13. // @Tags 地址
  14. // @Summary 提交系统信息
  15. // @Description 提交系统信息
  16. // @Accept json
  17. // @Produce json
  18. // @Param body body requstform.PeerForm true "系统信息表单"
  19. // @Success 200 {string} string "SYSINFO_UPDATED,ID_NOT_FOUND"
  20. // @Failure 500 {object} response.ErrorResponse
  21. // @Router /sysinfo [post]
  22. // @Security BearerAuth
  23. func (p *Peer) SysInfo(c *gin.Context) {
  24. f := &requstform.PeerForm{}
  25. err := c.ShouldBindBodyWith(f, binding.JSON)
  26. if err != nil {
  27. response.Error(c, err.Error())
  28. return
  29. }
  30. pe := service.AllService.PeerService.FindById(f.Id)
  31. if pe == nil || pe.RowId == 0 {
  32. pe = f.ToPeer()
  33. err = service.AllService.PeerService.Create(pe)
  34. if err != nil {
  35. response.Error(c, err.Error())
  36. return
  37. }
  38. }
  39. //SYSINFO_UPDATED 上传成功
  40. //ID_NOT_FOUND 下次心跳会上传
  41. //直接响应文本
  42. c.String(http.StatusOK, "")
  43. }