1 Star 0 Fork 20

第三方项目/aurora

forked from aurora-engine/aurora 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
httpmethod.go 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
aurora.io 提交于 2023-02-27 23:49 . 修改 web 包路径
package aurora
import (
"gitee.com/aurora-engine/web"
"net/http"
"strings"
)
// Get 请求
func (engine *Engine) Get(url string, control any, middleware ...web.Middleware) {
engine.register(http.MethodGet, url, control, middleware...)
}
// Post 请求
func (engine *Engine) Post(url string, control any, middleware ...web.Middleware) {
engine.register(http.MethodPost, url, control, middleware...)
}
// Put 请求
func (engine *Engine) Put(url string, control any, middleware ...web.Middleware) {
engine.register(http.MethodPut, url, control, middleware...)
}
// Delete 请求
func (engine *Engine) Delete(url string, control any, middleware ...web.Middleware) {
engine.register(http.MethodDelete, url, control, middleware...)
}
// Head 请求
func (engine *Engine) Head(url string, control any, middleware ...web.Middleware) {
engine.register(http.MethodHead, url, control, middleware...)
}
// register 通用注册器
func (engine *Engine) register(method string, url string, control any, middleware ...web.Middleware) {
engine.Route.Cache(method, url, control, middleware...)
}
// Group 路由分组 必须以 “/” 开头分组
// Group 和 Aurora 都有 相同的 http 方法注册
func (engine *Engine) Group(url string, middleware ...web.Middleware) *Group {
// 对头部没有添加 / 的路径 自动处理
if !strings.HasPrefix(url, "/") {
url = "/" + url
}
if strings.HasSuffix(url, "/") {
url = url[:len(url)-1]
}
//分组处理的 handles 和 群居的 handle 是区分开的,该处handle只作用于通过该分组创建的 接口,在调用接口之前该 handles会被执行
return &Group{
prefix: url,
a: engine,
middleware: middleware,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/project3_1/aurora.git
[email protected]:project3_1/aurora.git
project3_1
aurora
aurora
master

搜索帮助