Monday, May 19, 2025
HomeGolangGin dlv debugger would not work with my docker and vscode configuration...

Gin dlv debugger would not work with my docker and vscode configuration – Getting Assist


I attempt to setup dev setting for Gin framework utilizing docker and vscode. I can’t determine why the breakpoint is seen within the debug console however it doesn’t have impact. In docker I’m getting profitable response however breakpoint didn’t work: library-go-backend-1 | [GIN] 2024/07/21 - 10:06:11 | 200 | 440.125µs | 192.168.65.1 | GET "https://discussion board.golangbridge.org/"
I attempted to vary ports or use completely different choices in my setup however nonetheless no clue

Right here is my setup:
Dockerfile

FROM golang:1.22.1 AS builder
WORKDIR /app/
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go construct -o predominant .
#dlv
RUN CGO_ENABLED=0 go set up -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@newest

FROM alpine:newest
WORKDIR /app/
COPY --from=builder /app/predominant predominant
COPY --from=builder /go/bin/dlv /dlv

CMD ["/dlv", "--listen=:8081",  "--headless=true", "--continue", "--accept-multiclient", "--headless=true", "--api-version=2", "exec", "./main"]

docker-compose.yaml

companies:
  library-go-backend:
    construct: .
    ports:
      - 8080:8080
      - 8081:8081
    volumes:
      # - ./src:/app
      - ~/.dlv:/root/.dlv 

.vscode/lanuch.json

{
    "model": "0.2.0",
    "configurations": [
        {
			"name": "Launch",
			//"processId": 36840,
			"type": "go",
			"request": "attach",
			"mode": "remote",
			//"remotePath": "${workspaceRoot}/main.go",
			"port": 8081,
			"host": "127.0.0.1",
			"showLog": true,
			"trace": "log",
			"logOutput": "rpc""
        }
    ]
}

and this system could be very easy:

bundle predominant

import (
	"fmt"
	"internet/http"
	"pbuf/fashions"

	"github.com/gin-gonic/gin"
)

func sayOk(c *gin.Context) {
	fmt.Println(2 + 2) //<-breakpoint did not work
	c.JSON(http.StatusOK, gin.H{
		"standing": "okay",
	})
}

func GetDBContentTags(c *gin.Context) {
	contentTags := fashions.ListContentTags()
	c.JSON(http.StatusOK, contentTags)
}

func predominant() {
	router := gin.Default() // <- breakpoint did not work 
	router.StaticFile("/content_tag.proto", "./content_tag.proto")
	//router.GET("/albums", getAlbums)
	router.GET("https://discussion board.golangbridge.org/", sayOk)
	router.GET("/content_tags", GetDBContentTags)

	router.Run()
}

listed here are some additional logs from vscode debug console:

DisconnectRequest
Closing Delve.
Distant Debugging: shut dlv connection.
DisconnectRequest to father or mother to close down protocol server.
DisconnectResponse
Verbose logs are written to:
/var/folders/pl/md29lpmn1bn5cv11vk1s_wk80000gn/T/vscode-go-debug.txt
InitializeRequest
InitializeResponse
AttachRequest
Begin distant debugging: connecting 127.0.0.1:8081
InitializeEvent
ConfigurationDoneRequest
ConfigurationDoneResponse {"seq":12,"sort":"response","request_seq":3,"command":"configurationDone","success":true}
SetBreakPointsRequest
Halting earlier than setting breakpoints. SkipStopEventOnce is fake.
All cleared
Creating on: /Customers/tomasz/pbuf/predominant.go:19
All set:[{"Breakpoint":{"id":60,"name":"","addr":7225507,"addrs":[7225507],"addrpid":[11],"file":"/app/predominant.go","line":19,"functionName":"predominant.GetDBContentTags","ExprString":"","Cond":"","HitCond":"","HitCondPerG":false,"proceed":false,"traceReturn":false,"goroutine":false,"stacktrace":0,"LoadArgs":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"LoadLocals":{"FollowPointers":true,"MaxVariableRecurse":1,"MaxStringLen":64,"MaxArrayValues":64,"MaxStructFields":-1},"WatchExpr":"","WatchType":0,"hitCount":{},"totalHitCount":0,"disabled":false,"RootFuncName":"","TraceFollowCalls":0}}]
SetBreakPointsResponse

I ship

  • curl localhost:8080 which ends up with {"standing":"okay"}
  • curl localhost:8081curl: (52) Empty reply from server
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments