12 Star 145 Fork 20

aurora-engine/aurora

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
httpmethod.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
package aurora
import (
"gitee.com/aurora-engine/web"
"net/http"
"strings"
)
// Get 请求
func (engine *Engine) Get(url string, control any, interceptor ...web.Interceptor) {
engine.register(http.MethodGet, url, control, interceptor...)
}
// Post 请求
func (engine *Engine) Post(url string, control any, interceptor ...web.Interceptor) {
engine.register(http.MethodPost, url, control, interceptor...)
}
// Put 请求
func (engine *Engine) Put(url string, control any, interceptor ...web.Interceptor) {
engine.register(http.MethodPut, url, control, interceptor...)
}
// Delete 请求
func (engine *Engine) Delete(url string, control any, interceptor ...web.Interceptor) {
engine.register(http.MethodDelete, url, control, interceptor...)
}
// Head 请求
func (engine *Engine) Head(url string, control any, interceptor ...web.Interceptor) {
engine.register(http.MethodHead, url, control, interceptor...)
}
// register 通用注册器
func (engine *Engine) register(method string, url string, control any, interceptor ...web.Interceptor) {
engine.Route.Cache(method, url, control, interceptor...)
}
// Group 路由分组 必须以 “/” 开头分组
// Group 和 Aurora 都有 相同的 http 方法注册
func (engine *Engine) Group(url string, interceptor ...web.Interceptor) *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,
interceptor: interceptor,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/aurora-engine/aurora.git
git@gitee.com:aurora-engine/aurora.git
aurora-engine
aurora
aurora
v1.3.24

搜索帮助