With no testing, and no evidence that we did anything correctly, it appears the has cleaned up the api a little tiny bit
This commit is contained in:
parent
9ebc43e072
commit
b15a05676c
@ -3,6 +3,7 @@ package servlet
|
|||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -77,6 +78,12 @@ func (s *VinegarServlet) Start() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *VinegarServlet) PrintRoutes() {
|
||||||
|
for _, route := range s.Routes {
|
||||||
|
log.Println(route.Pattern.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func SendError(w http.ResponseWriter, code int, msg string) {
|
func SendError(w http.ResponseWriter, code int, msg string) {
|
||||||
errorFile := "templates/error.html"
|
errorFile := "templates/error.html"
|
||||||
errorResp := ErrorResponse{code, msg}
|
errorResp := ErrorResponse{code, msg}
|
||||||
|
|||||||
@ -18,20 +18,24 @@ type (
|
|||||||
|
|
||||||
func NewImageRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
func NewImageRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
||||||
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
|
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
|
||||||
imgRoute := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
|
route := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
|
||||||
rootRoute := NewServletRoute(urlPattern, createUncompressedFileServletFunction(&imgRoute, defaultPrune, pathlike))
|
rootRoute := NewServletRoute(urlPattern, createUncompressedFileServletFunction(&route, defaultPrune, pathlike))
|
||||||
imgRoute.VinegarRoute = rootRoute //i *kinda* don't like this pattern
|
route.VinegarRoute = rootRoute //i *kinda* don't like this pattern
|
||||||
return &imgRoute
|
|
||||||
|
servlet.AddRoute(route.VinegarRoute)
|
||||||
|
return &route
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
func NewTextRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
||||||
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
|
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
|
||||||
fr := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
|
route := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
|
||||||
textRouteHandler := createCompressibleFileServletFunction(&fr, defaultPrune, pathlike)
|
textRouteHandler := createCompressibleFileServletFunction(&route, defaultPrune, pathlike)
|
||||||
rootRoute := NewServletRoute(urlPattern, textRouteHandler) //i *still* kinda don't like this pattern
|
rootRoute := NewServletRoute(urlPattern, textRouteHandler) //i *still* kinda don't like this pattern
|
||||||
fr.VinegarRoute = rootRoute
|
route.VinegarRoute = rootRoute
|
||||||
|
|
||||||
return &fr
|
servlet.AddRoute(route.VinegarRoute)
|
||||||
|
|
||||||
|
return &route
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingleFileRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
func NewSingleFileRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
|
||||||
@ -49,6 +53,8 @@ func NewSingleFileRoute(servlet *VinegarServlet, urlPattern string, pathlike str
|
|||||||
|
|
||||||
route.VinegarRoute = parentRoute
|
route.VinegarRoute = parentRoute
|
||||||
|
|
||||||
|
servlet.AddRoute(route.VinegarRoute)
|
||||||
|
|
||||||
return &route
|
return &route
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user