From 2fe21452c7ec2763bca91ec1ccac85ebfa9f74c8 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 29 May 2026 19:38:12 -0400 Subject: [PATCH] Bump dependencies & drop web package --- go.mod | 6 +++--- go.sum | 8 ++++---- web/http.go | 57 ----------------------------------------------------- web/util.go | 21 -------------------- 4 files changed, 7 insertions(+), 85 deletions(-) delete mode 100644 web/http.go delete mode 100644 web/util.go diff --git a/go.mod b/go.mod index 1d55b85..d0424ce 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/rwinkhart/go-boilerplate -go 1.26.1 +go 1.26.3 -require golang.org/x/term v0.41.0 +require golang.org/x/term v0.43.0 -require golang.org/x/sys v0.42.0 // indirect +require golang.org/x/sys v0.45.0 // indirect diff --git a/go.sum b/go.sum index 91a25f5..96d3601 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= -golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= -golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= +golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= +golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4= +golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk= diff --git a/web/http.go b/web/http.go deleted file mode 100644 index 20318c6..0000000 --- a/web/http.go +++ /dev/null @@ -1,57 +0,0 @@ -package web - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/rwinkhart/go-boilerplate/back" -) - -// GenericResponse defines a generic status and message JSON response. -type GenericResponse struct { - Status string `json:"status"` - Message string `json:"message"` -} - -// WriteHTTPError writes an error status and message to an http ResponseWriter. -func WriteHTTPError(w *http.ResponseWriter, message string, responseCode int) { - jsonError := GenericResponse{ - Status: "error", - Message: message, - } - - // ERROR IGNORED - // Reason: Used in error handling path, thus this needs to be unable - // to fail (there would be no way to handle it gracefully). - output, _ := json.Marshal(jsonError) - - (*w).Header().Set("Content-Type", "application/json") - (*w).WriteHeader(http.StatusBadRequest) - (*w).Write(output) -} - -// WriteHTTPResponse writes a custom response to an http ResponseWriter. -func WriteHTTPResponse(w *http.ResponseWriter, unmarshaledResponse any) { - output, err := json.Marshal(unmarshaledResponse) - if err != nil { - WriteHTTPError(w, "Failed to marshal JSON: "+err.Error(), http.StatusInternalServerError) - return - } - (*w).Header().Set("Content-Type", "application/json") - (*w).WriteHeader(http.StatusOK) - (*w).Write(output) -} - -// LogAndVerifyRequest logs incoming HTTP requests -// and ensures the methods match what is expected. -// Returns: badMethod (bool) - if true, the method is not allowed and the handler should return. -func LogAndVerifyRequest(w *http.ResponseWriter, r *http.Request, expectedMethod string) bool { - if r.Method != expectedMethod { - WriteHTTPError(w, "Method not allowed", http.StatusMethodNotAllowed) - PrintLog(fmt.Sprintf("BAD method (expected: %s, got: %s) for request received on %s from %s", expectedMethod, r.Method, r.URL.Path, r.RemoteAddr), back.AnsiError) - return true - } - PrintLog(fmt.Sprintf("Request received on %s from %s", r.URL.Path, r.RemoteAddr), "") - return false -} diff --git a/web/util.go b/web/util.go deleted file mode 100644 index a2365db..0000000 --- a/web/util.go +++ /dev/null @@ -1,21 +0,0 @@ -package web - -import ( - "fmt" - "log" - "os" - - "github.com/rwinkhart/go-boilerplate/back" -) - -// PrintLog colorizes a log and determines the best method for printing it. -func PrintLog(message, ansiColor string) { - if ansiColor != "" { - message = ansiColor + message + back.AnsiReset - } - if os.Getenv("INVOCATION_ID") != "" { - fmt.Println(message) - } else { - log.Println(message) - } -}