gosora/gen_router.go

69 lines
2.0 KiB
Go
Raw Normal View History

// Code generated by. DO NOT EDIT.
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
package main
import "sync"
import "net/http"
type GenRouter struct {
UploadHandler func(http.ResponseWriter, *http.Request)
sync.RWMutex // Temporary Fallback
old_routes map[string]func(http.ResponseWriter, *http.Request) // Temporary Fallback
}
func NewGenRouter() *GenRouter {
fs_u := http.FileServer(http.Dir("./uploads"))
return &GenRouter{
UploadHandler: http.StripPrefix("/uploads/",fs_u).ServeHTTP,
old_routes: make(map[string]func(http.ResponseWriter, *http.Request)),
}
}
func (router *GenRouter) Handle(pattern string, handle http.Handler) {
router.Lock()
router.old_routes[pattern] = handle.ServeHTTP
router.Unlock()
}
func (router *GenRouter) HandleFunc(pattern string, handle func(http.ResponseWriter, *http.Request)) {
router.Lock()
router.old_routes[pattern] = handle
router.Unlock()
}
func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if req.URL.Path[0] != '/' {
w.WriteHeader(405)
w.Write([]byte(""))
return
}
var extra_data string
/*if req.URL.Path[len(req.URL.Path) - 1] != '/' {
extra_data = req.URL.Path[strings.LastIndexByte(req.URL.Path,'/') + 1:]
req.URL.Path = req.URL.Path[:strings.LastIndexByte(req.URL.Path,'/') + 1]
}*/
switch(req.URL.Path) {
case "/static/": route_static(w,req/*, req.URL.Path + extra_data*/)
case "/overview/": route_overview(w,req/**/)
case "/pages/": route_custom_page(w,req/*, &extra_data*/)
case "/topics/": route_topics(w,req/*, &groups, &forums*/)
case "/forums/": route_forums(w,req/*, &forums*/)
case "/uploads/": router.UploadHandler(w,req)
//default: NotFound(w,req)
}
// A fallback for the routes which haven't been converted to the new router yet
router.RLock()
handle, ok := router.old_routes[req.URL.Path]
if ok {
router.RUnlock()
req.URL.Path = req.URL.Path + extra_data
handle(w,req)
return
}
router.RUnlock()
NotFound(w,req)
}