From c2b5c15bb99d028ea8cd6e2361fd396219ecbbfa Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 4 Dec 2023 15:03:40 -0700 Subject: [PATCH] update git - moving to devdontainer --- .vscode/launch.json | 2 +- Dockerfile.debug | 6 ++++-- main/go.mod | 5 ++++- main/go.sum | 2 ++ main/main.go | 13 ++++++++++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4aee872..9246858 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "Go Debug - Local", "type": "go", "request": "launch", - "mode": "auto", + "mode": "debug", "program": "${file}", "args": [] }, diff --git a/Dockerfile.debug b/Dockerfile.debug index e90f354..04daa59 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -1,10 +1,12 @@ FROM golang:alpine +RUN CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest +# RUN CGO_ENABLED=0 go get -d github.com/gorilla/mux@latest + WORKDIR /app EXPOSE 80 4000 COPY ./main/* ./ -RUN CGO_ENABLED=0 go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest -RUN go install github.com/gorilla/mux +RUN go install github.com/gorilla/mux ENV GO111MODULE=off RUN CGO_ENABLED=0 go build -gcflags "all=-N -l" -o debug-app . diff --git a/main/go.mod b/main/go.mod index 255935a..f7611eb 100644 --- a/main/go.mod +++ b/main/go.mod @@ -2,4 +2,7 @@ module git.mpe.ca/eeckert/egnytewebhandler go 1.21.4 -require github.com/gorilla/mux v1.8.1 // indirect +require ( + github.com/gorilla/mux v1.8.1 + golang.org/x/text v0.14.0 +) diff --git a/main/go.sum b/main/go.sum index 7128337..eb8c2be 100644 --- a/main/go.sum +++ b/main/go.sum @@ -1,2 +1,4 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/main/main.go b/main/main.go index 37e611e..7c6dce8 100644 --- a/main/main.go +++ b/main/main.go @@ -5,6 +5,7 @@ import ( "io" "log" "net/http" + "time" "github.com/gorilla/mux" ) @@ -13,11 +14,17 @@ func readDataStream(resp http.ResponseWriter, request *http.Request) { reqBody, _ := io.ReadAll(request.Body) // var jsonBody = json.NewDecoder(request.Body) - fmt.Println(reqBody) + fmt.Println(string(reqBody)) } -func HealthCheck() { +func HealthCheck(resp http.ResponseWriter, request *http.Request) { + var t = time.Now().String() + var MessageText = t + ": Health Check from " + request.RemoteAddr + // reqBody, _ := io.ReadAll(request.Body) + fmt.Println(http.StatusOK, MessageText) + resp.WriteHeader(http.StatusOK) + resp.Write([]byte(MessageText)) } func handleRequests() { @@ -25,7 +32,7 @@ func handleRequests() { mainrouter := mux.NewRouter().StrictSlash(true) mainrouter.HandleFunc("/", readDataStream).Methods("POST") - // mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET") + mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET") log.Fatal(http.ListenAndServe(":10000", mainrouter))