h_hello.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package handler
  2. import (
  3. "cicv-data-closedloop/common/config/c_db"
  4. "cicv-data-closedloop/common/config/c_log"
  5. "cicv-data-closedloop/common/entity"
  6. "github.com/gin-gonic/gin"
  7. "net/http"
  8. )
  9. type testStruct struct {
  10. Id int `db:"id"`
  11. Name string `db:"name"`
  12. }
  13. // Hello 测试接口
  14. // @Tags 此标记的所有接口均用于测试
  15. // @Summary 测试
  16. // @Description 该接口用于测试使用
  17. // @Param param query int true "Id" 参数 :@Param 参数名 位置(query 或者 path或者 body) 类型 是否必需 注释
  18. // @Produce json
  19. // @Success 200 {object} entity.HttpResult
  20. // @Router /test/hello [get]
  21. func Hello(c *gin.Context) {
  22. // 获取请求参数
  23. param := c.Query("param")
  24. c_log.GlobalLogger.Info("接受到请求参数:", param)
  25. var tests []testStruct
  26. // 查询数据库
  27. var testSql string
  28. if err := c_db.MysqlDb.Select(&tests, testSql); err != nil {
  29. c_log.GlobalLogger.Error("数据库查询报错:", err)
  30. c.JSON(http.StatusInternalServerError, entity.DefaultFailHttpResult)
  31. return
  32. }
  33. c_log.GlobalLogger.Info("数据库查询成功:", tests)
  34. c.JSON(http.StatusOK, entity.DefaultSuccessHttpResult)
  35. }