2024-10-14 13:49:16 +08:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"catface/app/global/consts"
"catface/app/utils/response"
"github.com/gin-gonic/gin"
)
type Home struct {
}
// 1.门户类首页新闻
func (u *Home) News(context *gin.Context) {
// 由于本项目骨架已经将表单验证器的字段(成员)绑定在上下文,因此可以按照 GetString()、GetInt64()、GetFloat64等快捷获取需要的数据类型
// 当然也可以通过gin框架的上下文原原始方法获取例如 context.PostForm("name") 获取,这样获取的数据格式为文本,需要自己继续转换
newsType := context.GetString(consts.ValidatorPrefix + "newsType")
page := context.GetFloat64(consts.ValidatorPrefix + "page")
limit := context.GetFloat64(consts.ValidatorPrefix + "limit")
userIp := context.ClientIP()
ref := context.GetHeader("Referer")
// 这里随便模拟一条数据返回
response.Success(context, "ok", gin.H{
"newsType": newsType,
"page": page,
"limit": limit,
"userIp": userIp,
"title": "门户首页公司新闻标题001",
"content": "门户新闻内容001",
"referer": ref,
})
}