55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package framework
|
|
|
|
// IGroup prefix routes
|
|
type IGroup interface {
|
|
Get(string, ...ControllerHandler)
|
|
Post(string, ...ControllerHandler)
|
|
Put(string, ...ControllerHandler)
|
|
Delete(string, ...ControllerHandler)
|
|
Use(...ControllerHandler)
|
|
}
|
|
|
|
// Group is the implementation of IGroup interface
|
|
type Group struct {
|
|
core *Core
|
|
prefix string
|
|
middlewares []ControllerHandler
|
|
}
|
|
|
|
// NewGroup create a new prefix group
|
|
func NewGroup(core *Core, prefix string) *Group {
|
|
return &Group{
|
|
core: core,
|
|
prefix: prefix,
|
|
}
|
|
}
|
|
|
|
// Get is a simple get router of the group
|
|
func (g *Group) Get(url string, handlers ...ControllerHandler) {
|
|
allHandlers := append(g.middlewares, handlers...)
|
|
g.core.Get(g.prefix+url, allHandlers...)
|
|
}
|
|
|
|
// Post is a simple post router of the group
|
|
func (g *Group) Post(url string, handlers ...ControllerHandler) {
|
|
allHandlers := append(g.middlewares, handlers...)
|
|
g.core.Post(g.prefix+url, allHandlers...)
|
|
}
|
|
|
|
// Put is a simple put router of the group
|
|
func (g *Group) Put(url string, handlers ...ControllerHandler) {
|
|
allHandlers := append(g.middlewares, handlers...)
|
|
g.core.Put(g.prefix+url, allHandlers...)
|
|
}
|
|
|
|
// Delete is a simple delete router of the group
|
|
func (g *Group) Delete(url string, handlers ...ControllerHandler) {
|
|
allHandlers := append(g.middlewares, handlers...)
|
|
g.core.Delete(g.prefix+url, allHandlers...)
|
|
}
|
|
|
|
// Use registers middlewares
|
|
func (g *Group) Use(middlewares ...ControllerHandler) {
|
|
g.middlewares = append(g.middlewares, middlewares...)
|
|
}
|