2017-11-10 00:16:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
type RouteImpl struct {
|
2017-11-12 07:18:25 +00:00
|
|
|
Name string
|
|
|
|
Path string
|
|
|
|
Vars []string
|
|
|
|
MemberAction bool
|
|
|
|
RunBefore []Runnable
|
|
|
|
|
|
|
|
Parent *RouteGroup
|
2017-11-10 00:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Runnable struct {
|
|
|
|
Contents string
|
|
|
|
Literal bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func addRoute(route *RouteImpl) {
|
|
|
|
routeList = append(routeList, route)
|
|
|
|
}
|
|
|
|
|
2017-11-10 03:33:11 +00:00
|
|
|
func (route *RouteImpl) Before(items ...string) *RouteImpl {
|
|
|
|
for _, item := range items {
|
|
|
|
route.RunBefore = append(route.RunBefore, Runnable{item, false})
|
|
|
|
}
|
|
|
|
return route
|
|
|
|
}
|
|
|
|
|
|
|
|
func (route *RouteImpl) LitBefore(items ...string) *RouteImpl {
|
|
|
|
for _, item := range items {
|
|
|
|
route.RunBefore = append(route.RunBefore, Runnable{item, true})
|
2017-11-10 00:16:15 +00:00
|
|
|
}
|
|
|
|
return route
|
|
|
|
}
|
|
|
|
|
2017-11-12 07:18:25 +00:00
|
|
|
func (route *RouteImpl) hasBefore(items ...string) bool {
|
|
|
|
for _, item := range items {
|
|
|
|
for _, before := range route.RunBefore {
|
|
|
|
if before.Contents == item {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-10 00:16:15 +00:00
|
|
|
func addRouteGroup(routeGroup *RouteGroup) {
|
|
|
|
routeGroups = append(routeGroups, routeGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
func blankRoute() *RouteImpl {
|
2017-11-12 07:18:25 +00:00
|
|
|
return &RouteImpl{"", "", []string{}, false, []Runnable{}, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func View(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
return &RouteImpl{fname, path, args, false, []Runnable{}, nil}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MemberView(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
route := &RouteImpl{fname, path, args, false, []Runnable{}, nil}
|
|
|
|
if !route.hasBefore("SuperModOnly", "AdminOnly") {
|
|
|
|
route.Before("MemberOnly")
|
|
|
|
}
|
|
|
|
return route
|
|
|
|
}
|
|
|
|
|
|
|
|
func ModView(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
route := &RouteImpl{fname, path, args, false, []Runnable{}, nil}
|
|
|
|
if !route.hasBefore("AdminOnly") {
|
|
|
|
route.Before("SuperModOnly")
|
|
|
|
}
|
|
|
|
return route
|
|
|
|
}
|
|
|
|
|
|
|
|
func Action(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
route := &RouteImpl{fname, path, args, true, []Runnable{}, nil}
|
|
|
|
route.Before("NoSessionMismatch")
|
|
|
|
if !route.hasBefore("SuperModOnly", "AdminOnly") {
|
|
|
|
route.Before("MemberOnly")
|
|
|
|
}
|
|
|
|
return route
|
|
|
|
}
|
|
|
|
|
|
|
|
func AnonAction(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
route := &RouteImpl{fname, path, args, false, []Runnable{}, nil}
|
|
|
|
route.Before("ParseForm")
|
|
|
|
return route
|
2017-11-10 00:16:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 07:18:25 +00:00
|
|
|
func UploadAction(fname string, path string, args ...string) *RouteImpl {
|
|
|
|
route := &RouteImpl{fname, path, args, true, []Runnable{}, nil}
|
|
|
|
if !route.hasBefore("SuperModOnly", "AdminOnly") {
|
|
|
|
route.Before("MemberOnly")
|
|
|
|
}
|
|
|
|
return route
|
2017-11-10 00:16:15 +00:00
|
|
|
}
|