From 98eb550f9ad75a75705c0ec0c5a46e3f347e2600 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Sun, 18 Mar 2018 05:46:12 +0100 Subject: [PATCH] Add debugging utilities --- Dockerfile | 4 ++-- main.go | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f58401..cf7f589 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ RUN apk add --no-cache curl git gcc musl-dev RUN curl https://glide.sh/get | sh WORKDIR /go/src/app -COPY *.go . -COPY glide.* . +COPY *.go ./ +COPY glide.* ./ RUN glide install RUN CGO_ENABLED=false go build -a app . diff --git a/main.go b/main.go index 5dbedac..127f7bd 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,19 @@ import ( "github.com/go-redis/redis" _ "github.com/lib/pq" "net/http" + "fmt" ) +func headerWrapper(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + println(r.URL.Path) + for key, value := range r.Header { + fmt.Printf("%s: %s", key, value) + } + handler.ServeHTTP(w, r) + }) +} + func main() { config := NewConfigFromEnv() @@ -26,17 +37,17 @@ func main() { http.FileServer(http.Dir("assets")), } - http.Handle("/upload/", pageUpload(pageContext)) + http.Handle("/upload/", headerWrapper(pageUpload(pageContext))) - http.Handle("/i/", http.StripPrefix("/i/", pageImageDetail(pageContext))) - http.Handle("/me/i/", http.StripPrefix("/me/i/", pageImageDetail(pageContext))) + http.Handle("/i/", headerWrapper(http.StripPrefix("/i/", pageImageDetail(pageContext)))) + http.Handle("/me/i/", headerWrapper(http.StripPrefix("/me/i/", pageImageDetail(pageContext)))) - http.Handle("/a/", http.StripPrefix("/a/", pageAlbumDetail(pageContext))) - http.Handle("/me/a/", http.StripPrefix("/me/a/", pageAlbumDetail(pageContext))) + http.Handle("/a/", headerWrapper(http.StripPrefix("/a/", pageAlbumDetail(pageContext)))) + http.Handle("/me/a/", headerWrapper(http.StripPrefix("/me/a/", pageAlbumDetail(pageContext)))) - http.Handle("/me/images/", pageImageList(pageContext)) - http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets")))) - http.Handle("/", pageIndex(pageContext)) + http.Handle("/me/images/", headerWrapper(pageImageList(pageContext))) + http.Handle("/assets/", headerWrapper(http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))) + http.Handle("/", headerWrapper(pageIndex(pageContext))) http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("OK")) -- GitLab