diff options
| author | Xe Iaso <me@xeiaso.net> | 2025-01-25 11:29:39 -0500 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2025-01-25 11:29:39 -0500 |
| commit | 84a2cb246c5c6172c2499f57a43cbc898d4e2c3f (patch) | |
| tree | d2c280933b9b31016580ae35f1e5f6d49c3e1717 /cmd | |
| parent | cd00641150ebf27dd09a8da99d75b25815030cfd (diff) | |
| download | x-84a2cb246c5c6172c2499f57a43cbc898d4e2c3f.tar.xz x-84a2cb246c5c6172c2499f57a43cbc898d4e2c3f.zip | |
make simpleapp helm template
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/httpdebug/main.go | 31 |
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)) } |
