dvfs agent 0.1

This commit is contained in:
2026-04-26 12:38:53 +02:00
commit d0b12d668d
5 changed files with 232 additions and 0 deletions

24
agent/helpers.go Normal file
View 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)
}
}