Encore makes it easy to debug your application using Delve.
First, make sure you have
dlv installed by running (Go 1.16 and later):
$ go install github.com/go-delve/delve/cmd/dlv@latest
Next, run your Encore application with
encore run --debug. This will cause Encore to print the Process ID to the terminal, which you will use to attach your debugger:
$ encore run --debugAPI Base URL: http://localhost:4000Dev Dashboard URL: http://localhost:9400/hello-world-cgu2Process ID: 518941:48PM INF registered endpoint path=/hello/:name service=hello endpoint=Hello
(Your process id will differ).
When your Encore application is running, it’s time to attach the debugger. The instructions differ depending on how you would like to debug (in your terminal or in your editor). If instructions for your editor aren’t listed below, consult your editor for information on how to attach a debugger to a running process.
To debug in your terminal, run
dlv attach $PID (replace
$PID with your Process ID from the previous step). You should see:
$ dlv attach 51894Type 'help' for list of commands.(dlv)
To debug with VS Code you must first add a debug configuration. Press
Run -> Add Configuration, choose
Go -> Attach to local process. In the generated configuration, you should see
"processId": 0 as a field. Replace
0 with the process id from above.
Next, open the Run and Debug menu in the toolbar on the left, select Attach to Process (the configuration you just created), and then press the green arrow.
That’s it! You should be able to set breakpoints and have the Encore application pause when they’re hit like you would expect.