1 Star 0 Fork 0

hongzhaomin / ginplus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
icontroller.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
hongzhaomin 提交于 2023-06-19 00:27 . 支持响应html控制器
package ginplus
type IController interface {
RequestMapping() string
}
// 编译校验:确保 RestController 完全实现了 IController 接口所有方法,如果有遗漏,编译报错
var _ IController = (*RestController)(nil)
// RestController 继承该控制器的结构体给浏览器返回JSON类型数据
// 示例代码:ctx.JSON(http.StatusOK, nil)
type RestController struct {
Path string
}
func (rc RestController) RequestMapping() string {
return rc.Path
}
// 编译校验:确保 Controller 完全实现了 IController 接口所有方法,如果有遗漏,编译报错
var _ IController = (*Controller)(nil)
// Controller 继承该控制器的结构体可以跳转html页面,给浏览器返回html类型响应
// 示例代码:ctx.HTML(http.StatusOK, "index.html", nil)
type Controller struct {
Path string
}
func (rc Controller) RequestMapping() string {
return rc.Path
}
// ModelAndView 使用Controller作为父类控制器时的返回值
// 也可以返回string,会被当作html路径解析
type ModelAndView struct {
View string `json:"view"` // html路径
Model any `json:"model"` // 渲染的参数
HttpStatus int `json:"httpStatus"` // http响应码
}
Go
1
https://gitee.com/hongzhaomin/ginplus.git
git@gitee.com:hongzhaomin/ginplus.git
hongzhaomin
ginplus
ginplus
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891