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)
	}
}
