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:
dtookey 2022-07-21 09:04:37 -04:00
parent 9ebc43e072
commit b15a05676c
3 changed files with 21 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package servlet
import (
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
"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) {
errorFile := "templates/error.html"
errorResp := ErrorResponse{code, msg}

View File

@ -18,20 +18,24 @@ type (
func NewImageRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
imgRoute := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
rootRoute := NewServletRoute(urlPattern, createUncompressedFileServletFunction(&imgRoute, defaultPrune, pathlike))
imgRoute.VinegarRoute = rootRoute //i *kinda* don't like this pattern
return &imgRoute
route := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
rootRoute := NewServletRoute(urlPattern, createUncompressedFileServletFunction(&route, defaultPrune, pathlike))
route.VinegarRoute = rootRoute //i *kinda* don't like this pattern
servlet.AddRoute(route.VinegarRoute)
return &route
}
func NewTextRoute(servlet *VinegarServlet, urlPattern string, pathlike string, useCache bool) *FileRoute {
defaultPrune := strings.Replace(urlPattern, ".*", "", -1)
fr := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
textRouteHandler := createCompressibleFileServletFunction(&fr, defaultPrune, pathlike)
route := FileRoute{srv: servlet, fileRoot: pathlike, UseCache: useCache}
textRouteHandler := createCompressibleFileServletFunction(&route, defaultPrune, pathlike)
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 {
@ -49,6 +53,8 @@ func NewSingleFileRoute(servlet *VinegarServlet, urlPattern string, pathlike str
route.VinegarRoute = parentRoute
servlet.AddRoute(route.VinegarRoute)
return &route
}

9
tmp.go
View File

@ -1,9 +0,0 @@
package main
import "vinegar/servlet"
func main() {
serv := servlet.NewServlet(":8080")
serv.Start()
}