From cb81c7fd6367d60aa07a10970174224ff7d4b0c4 Mon Sep 17 00:00:00 2001 From: eeckert Date: Mon, 4 Dec 2023 08:37:53 -0700 Subject: [PATCH] first push - trying to get live debug going. --- .vscode/launch.json | 21 +++++++++++++++++++++ Dockerfile | 9 +++++++++ Dockerfile.debug | 11 +++++++++++ main/go.mod | 5 +++++ main/go.sum | 2 ++ main/main.go | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 Dockerfile create mode 100644 Dockerfile.debug create mode 100644 main/go.mod create mode 100644 main/go.sum create mode 100644 main/main.go diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4aee872 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Go Debug - Local", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${file}", + "args": [] + }, + { + "name": "Go Debug - Docker", + "type": "go", + "request": "attach", + "mode": "remote", + "port": 4000, + "host": "127.0.0.1" + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..597b745 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:alpine +WORKDIR /app +EXPOSE 80 + +COPY main.go ./ +ENV GO111MODULE=off +RUN go build -o hello-app . + +CMD [ "./hello-app" ] \ No newline at end of file diff --git a/Dockerfile.debug b/Dockerfile.debug new file mode 100644 index 0000000..e90f354 --- /dev/null +++ b/Dockerfile.debug @@ -0,0 +1,11 @@ +FROM golang:alpine +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 +ENV GO111MODULE=off +RUN CGO_ENABLED=0 go build -gcflags "all=-N -l" -o debug-app . + +CMD [ "/go/bin/dlv", "--listen=:4000", "--headless=true", "--log=true", "--accept-multiclient", "--api-version=2", "exec", "/app/debug-app" ] \ No newline at end of file diff --git a/main/go.mod b/main/go.mod new file mode 100644 index 0000000..255935a --- /dev/null +++ b/main/go.mod @@ -0,0 +1,5 @@ +module git.mpe.ca/eeckert/egnytewebhandler + +go 1.21.4 + +require github.com/gorilla/mux v1.8.1 // indirect diff --git a/main/go.sum b/main/go.sum new file mode 100644 index 0000000..7128337 --- /dev/null +++ b/main/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= diff --git a/main/main.go b/main/main.go new file mode 100644 index 0000000..37e611e --- /dev/null +++ b/main/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "io" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +func readDataStream(resp http.ResponseWriter, request *http.Request) { + reqBody, _ := io.ReadAll(request.Body) + + // var jsonBody = json.NewDecoder(request.Body) + fmt.Println(reqBody) +} + +func HealthCheck() { + +} + +func handleRequests() { + // Start new Mux router + mainrouter := mux.NewRouter().StrictSlash(true) + + mainrouter.HandleFunc("/", readDataStream).Methods("POST") + // mainrouter.HandleFunc("/healthcheck", HealthCheck).Methods("GET") + + log.Fatal(http.ListenAndServe(":10000", mainrouter)) + +} + +func main() { + fmt.Println("MPE x Egnyte x PowerApps - Mux Router") + handleRequests() +}