dvfs agent 0.1
This commit is contained in:
24
agent/helpers.go
Normal file
24
agent/helpers.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// getStrippedRequestPath returns the request Path with the given prefix removed
|
||||
func getStrippedRequestPath(url *url.URL, prefix string) string {
|
||||
return strings.TrimPrefix(url.Path, prefix)
|
||||
}
|
||||
|
||||
func writeResponse(response string, status int, w http.ResponseWriter, logger *slog.Logger) {
|
||||
if status != http.StatusOK {
|
||||
w.WriteHeader(status)
|
||||
}
|
||||
_, err := w.Write([]byte(response))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
logger.Error("failed to write response", "err", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user