From a438590f92681512ea751bf88f092b7816e266e2 Mon Sep 17 00:00:00 2001 From: dtookey Date: Fri, 12 Aug 2022 10:54:40 -0400 Subject: [PATCH 1/3] shortened up the LRU cache timeout to 5 minutes --- vinegarUtil/webLRU.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vinegarUtil/webLRU.go b/vinegarUtil/webLRU.go index 6e48ea6..18f8cd1 100644 --- a/vinegarUtil/webLRU.go +++ b/vinegarUtil/webLRU.go @@ -9,7 +9,7 @@ import ( ) const ( - DefaultCacheTimeInMinutes = 15 + DefaultCacheTimeInMinutes = 5 ) type ( From 3ed33dfac9437d98cd9b304ab7174d1daa264fda Mon Sep 17 00:00:00 2001 From: dtookey Date: Mon, 15 Aug 2022 13:45:30 -0400 Subject: [PATCH 2/3] enabled more robust logging during errors --- servlet/server.go | 6 +++--- servlet/staticRoute.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/servlet/server.go b/servlet/server.go index 24ddbf3..078830f 100644 --- a/servlet/server.go +++ b/servlet/server.go @@ -72,7 +72,7 @@ func (s *VinegarServlet) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } } - s.SendError(w, 404, "Couldn't find your content.") + s.SendError(w, req, 404, "Couldn't find your content.") } func (s *VinegarServlet) Start() { @@ -95,8 +95,8 @@ func (r *VinegarRoute) Announce() { log.Printf("Added route for [%s]\n", r.Pattern.String()) } -func (s *VinegarServlet) SendError(w http.ResponseWriter, code int, msg string) { - fmt.Printf("Reached SendError. Rendering template for code %d with message: %s\n", code, msg) +func (s *VinegarServlet) SendError(w http.ResponseWriter, req *http.Request, code int, msg string) { + fmt.Printf("[%d][%s]. Rendering template for code %d with message: %s\n", code, req.URL.Path, code, msg) tmpl, exists := s.ErrorRoutes[code] if exists { tmpl.TemplateManager.AddMixin("code", strconv.Itoa(code)) diff --git a/servlet/staticRoute.go b/servlet/staticRoute.go index 1fd7d19..cb64bd8 100644 --- a/servlet/staticRoute.go +++ b/servlet/staticRoute.go @@ -73,7 +73,7 @@ func createSingleFileServletFunction(route *FileRoute) VinegarHandlerFunction { } if !exists { - route.srv.SendError(w, 404, "File not found.") + route.srv.SendError(w, req, 404, "File not found.") return } @@ -114,7 +114,7 @@ func createCompressibleFileServletFunction(route *FileRoute, basePattern string, return } } else { - route.srv.SendError(w, 404, "Couldn't find your content.") + route.srv.SendError(w, req, 404, "Couldn't find your content.") return } } @@ -154,7 +154,7 @@ func createUncompressedFileServletFunction(route *FileRoute, basePattern string, return } else { - route.srv.SendError(w, 404, "Couldn't find your content.") + route.srv.SendError(w, req, 404, "Couldn't find your content.") } } return fun From e2a686fb659d1f6c38408c366f1c9a377c4333e3 Mon Sep 17 00:00:00 2001 From: dtookey Date: Tue, 16 Aug 2022 11:38:23 -0400 Subject: [PATCH 3/3] added error logging into the SendError call --- servlet/server.go | 6 ++++-- servlet/staticRoute.go | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/servlet/server.go b/servlet/server.go index 078830f..73ca5cd 100644 --- a/servlet/server.go +++ b/servlet/server.go @@ -1,6 +1,7 @@ package servlet import ( + "errors" "fmt" "geniuscartel.xyz/vinegar/vinegarUtil" "log" @@ -72,7 +73,7 @@ func (s *VinegarServlet) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } } - s.SendError(w, req, 404, "Couldn't find your content.") + s.SendError(w, req, 404, "Couldn't find your content.", errors.New("failed to match route for ["+path+"]")) } func (s *VinegarServlet) Start() { @@ -95,8 +96,9 @@ func (r *VinegarRoute) Announce() { log.Printf("Added route for [%s]\n", r.Pattern.String()) } -func (s *VinegarServlet) SendError(w http.ResponseWriter, req *http.Request, code int, msg string) { +func (s *VinegarServlet) SendError(w http.ResponseWriter, req *http.Request, code int, msg string, aErr error) { fmt.Printf("[%d][%s]. Rendering template for code %d with message: %s\n", code, req.URL.Path, code, msg) + fmt.Println(aErr) tmpl, exists := s.ErrorRoutes[code] if exists { tmpl.TemplateManager.AddMixin("code", strconv.Itoa(code)) diff --git a/servlet/staticRoute.go b/servlet/staticRoute.go index cb64bd8..a446f44 100644 --- a/servlet/staticRoute.go +++ b/servlet/staticRoute.go @@ -1,6 +1,7 @@ package servlet import ( + "errors" util "geniuscartel.xyz/vinegar/vinegarUtil" "net/http" "path" @@ -73,7 +74,7 @@ func createSingleFileServletFunction(route *FileRoute) VinegarHandlerFunction { } if !exists { - route.srv.SendError(w, req, 404, "File not found.") + route.srv.SendError(w, req, 404, "File not found.", errors.New("could not find file: "+route.fileRoot)) return } @@ -114,7 +115,7 @@ func createCompressibleFileServletFunction(route *FileRoute, basePattern string, return } } else { - route.srv.SendError(w, req, 404, "Couldn't find your content.") + route.srv.SendError(w, req, 404, "Couldn't find your content.", errors.New("could not find valid file at ["+resourcePath+"]")) return } } @@ -154,7 +155,7 @@ func createUncompressedFileServletFunction(route *FileRoute, basePattern string, return } else { - route.srv.SendError(w, req, 404, "Couldn't find your content.") + route.srv.SendError(w, req, 404, "Couldn't find your content.", errors.New("could not find file for ["+stub+"]")) } } return fun