AFAIRE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### kong ####### Copyright (c) 2021-2022 losyme ################################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package router
import "net/http"
type Group struct {
sr *SubRouter
path string
}
func (g *Group) New(path string, fn func(*Group)) {
fn(&Group{
sr: g.sr,
path: g.path + path,
})
}
func (g *Group) Use(mdlw ...Middleware) {
seg := g.sr.findSegment(g.path)
seg.middlewares = append(seg.middlewares, mdlw...)
}
func (g *Group) Add(method, path string, handler HandlerFunc) {
g.sr.Add(method, g.path+path, handler)
}
func (g *Group) Any(path string, handler HandlerFunc) {
g.Add("*", path, handler)
}
func (g *Group) Delete(path string, handler HandlerFunc) {
g.Add(http.MethodDelete, path, handler)
}
func (g *Group) Get(path string, handler HandlerFunc) {
g.Add(http.MethodGet, path, handler)
}
func (g *Group) Head(path string, handler HandlerFunc) {
g.Add(http.MethodHead, path, handler)
}
func (g *Group) Options(path string, handler HandlerFunc) {
g.Add(http.MethodOptions, path, handler)
}
func (g *Group) Patch(path string, handler HandlerFunc) {
g.Add(http.MethodPatch, path, handler)
}
func (g *Group) Post(path string, handler HandlerFunc) {
g.Add(http.MethodPost, path, handler)
}
func (g *Group) Put(path string, handler HandlerFunc) {
g.Add(http.MethodPut, path, handler)
}
/*
######################################################################################################## @(°_°)@ #######
*/