gosora/router_gen/route_group.go
Azareal 9f273a99f5 Trying to reduce the amount of UserCheck() boilerplate in the routes.
Reduced the amount of boilerplate in routes with renderTemplate()
Reduced the amount of boilerplate in routes with ParseSEOURL()
Removed some dated commented bits of code.
Used StashConfig in a few more places in the benchmarks to reduce the amount of boilerplate.

Renamed the pre_render_forum_list hook to pre_render_forums.
Renamed the pre_render_topic_list hook to pre_render_topics.
Renamed a few benchmark variables to simplify the code.
2018-11-12 19:23:36 +10:00

66 lines
1.4 KiB
Go

package main
type RouteGroup struct {
Path string
RouteList []*RouteImpl
RunBefore []Runnable
NoHead bool
}
func newRouteGroup(path string, routes ...*RouteImpl) *RouteGroup {
group := &RouteGroup{Path: path}
for _, route := range routes {
route.Parent = group
group.RouteList = append(group.RouteList, route)
}
return group
}
func (group *RouteGroup) Not(path ...string) *RouteSubset {
routes := make([]*RouteImpl, len(group.RouteList))
copy(routes, group.RouteList)
for i, route := range routes {
if inStringList(route.Path, path) {
routes = append(routes[:i], routes[i+1:]...)
}
}
return &RouteSubset{routes}
}
func inStringList(needle string, list []string) bool {
for _, item := range list {
if item == needle {
return true
}
}
return false
}
func (group *RouteGroup) NoHeader() *RouteGroup {
group.NoHead = true
return group
}
func (group *RouteGroup) Before(lines ...string) *RouteGroup {
for _, line := range lines {
group.RunBefore = append(group.RunBefore, Runnable{line, false})
}
return group
}
func (group *RouteGroup) LitBefore(lines ...string) *RouteGroup {
for _, line := range lines {
group.RunBefore = append(group.RunBefore, Runnable{line, true})
}
return group
}
func (group *RouteGroup) Routes(routes ...*RouteImpl) *RouteGroup {
for _, route := range routes {
route.Parent = group
group.RouteList = append(group.RouteList, route)
}
return group
}