34ca7de946
Refactored the router generator. Added the NoBanned and NoSessionMismatch middlewares. Removed some of the implicit returns. Refactored some of the routes and their associated stores. Added more Codebeat exclusions. Added the AddReply method to *Topic. Added the Like method to *Topic. MemberOnly now emits a LoginRequired error rather than a generic NoPermissions error. Made progress with Cosora, this time with the profile system.
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package main
|
|
|
|
type RouteGroup struct {
|
|
Path string
|
|
RouteList []*RouteImpl
|
|
RunBefore []Runnable
|
|
}
|
|
|
|
func newRouteGroup(path string, routes ...*RouteImpl) *RouteGroup {
|
|
return &RouteGroup{path, routes, []Runnable{}}
|
|
}
|
|
|
|
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) Before(line string, literal ...bool) *RouteGroup {
|
|
var litItem bool
|
|
if len(literal) > 0 {
|
|
litItem = literal[0]
|
|
}
|
|
group.RunBefore = append(group.RunBefore, Runnable{line, litItem})
|
|
return group
|
|
}
|
|
|
|
func (group *RouteGroup) Routes(routes ...*RouteImpl) *RouteGroup {
|
|
group.RouteList = append(group.RouteList, routes...)
|
|
return group
|
|
}
|