aboutsummaryrefslogtreecommitdiff
path: root/cmd/httpdebug
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2025-01-25 11:29:39 -0500
committerXe Iaso <me@xeiaso.net>2025-01-25 11:29:39 -0500
commit84a2cb246c5c6172c2499f57a43cbc898d4e2c3f (patch)
treed2c280933b9b31016580ae35f1e5f6d49c3e1717 /cmd/httpdebug
parentcd00641150ebf27dd09a8da99d75b25815030cfd (diff)
downloadx-84a2cb246c5c6172c2499f57a43cbc898d4e2c3f.tar.xz
x-84a2cb246c5c6172c2499f57a43cbc898d4e2c3f.zip
make simpleapp helm template
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/httpdebug')
-rw-r--r--cmd/httpdebug/main.go31
1 files changed, 24 insertions, 7 deletions
diff --git a/cmd/httpdebug/main.go b/cmd/httpdebug/main.go
index 1f7a042..8162bc2 100644
--- a/cmd/httpdebug/main.go
+++ b/cmd/httpdebug/main.go
@@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"
"os"
+ "strings"
"within.website/x/internal"
)
@@ -19,12 +20,28 @@ var (
func main() {
internal.HandleStartup()
+ mux := http.NewServeMux()
+
+ mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) {
+ fmt.Fprintln(w, "OK")
+ })
+
+ mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ contains := strings.Contains(r.Header.Get("Accept"), "text/html")
+
+ if contains {
+ w.Header().Add("Content-Type", "text/html")
+ fmt.Fprint(w, "<pre id=\"main\"><code>")
+ }
+
+ fmt.Println("---")
+ r.Write(io.MultiWriter(w, os.Stdout))
+
+ if contains {
+ fmt.Fprintln(w, "</pre></code>")
+ }
+ })
+
slog.Info("listening", "url", "http://localhost"+*bind)
- log.Fatal(http.ListenAndServe(*bind, http.HandlerFunc(
- func(w http.ResponseWriter, r *http.Request) {
- fmt.Println("---")
- r.Write(io.MultiWriter(w, os.Stdout))
- fmt.Println("---")
- },
- )))
+ log.Fatal(http.ListenAndServe(*bind, mux))
}