# Using Goland Debugger

**URL:** https://heroiclabs.com/docs/nakama/guides/server-framework/debugging-with-delve/goland-debugger/
**Summary:** Companion guide to Debugging with Delve showing  how you can debug your custom Go server runtime code using Delve inside a Docker container via Goland.
**Keywords:** debugging, debugging delve, go delve, delve, dlv, remote debugging, dlv cli, docker container, server runtime, goland
**Categories:** nakama, debugging-with-delve, server-framework

---


{{< note "warning" "Important Notes" >}}
- **ARM Users** - Using Delve on ARM architecture is unstable, consider debugging with another architecture.
- **Nakama Version** - This guide uses Nakama 3.22 version in the code examples. You can use any version of Nakama on your own environment. You can find all Nakama releases from [here](../../../../getting-started/release-notes).
  {{< / note >}}

# Using GoLand Debugger

With some minor modifications to the directions in the [Debugging with Delve](../) guide, you can debug your custom Go server runtime code using Delve inside a Docker container via GoLand.

Due to some limitations of the GoLand Debugger, you must install the [Dlvx Plugin](https://plugins.jetbrains.com/plugin/23495-dlvx). To do this, go to **GoLand** > **Settings** > **Plugins** > **Search** for "Dlvx" > Press **Install**.

## Dockerfile

The same Dockerfile is used, with the only change being the removal of the `ENTRYPOINT` line:

```dockerfile
FROM heroiclabs/nakama-pluginbuilder:3.22.0 AS builder

ENV GO111MODULE on
ENV CGO_ENABLED 1
ENV GOPRIVATE "hiro/guides"

WORKDIR /backend
COPY . .

RUN go build --trimpath --gcflags "all=-N -l" --buildmode=plugin -o ./backend.so
RUN go install github.com/go-delve/delve/cmd/dlv@latest

FROM heroiclabs/nakama-dsym:3.22.0

COPY --from=builder /go/bin/dlv /nakama
COPY --from=builder /backend/backend.so /nakama/data/modules
COPY --from=builder /backend/local.yml /nakama/data/

```

## Docker Compose file

In the Docker Compose file, we add the `entrypoint` property to the `nakama` server and set it to run the container using the `dlv` command. We also add the Delve port (`4000`) to the `ports` property.

```yaml
version: '3.9'
services:
  postgres:
    container_name: game_backend_postgres
    command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    expose:
      - "8080"
      - "5432"
    healthcheck:
      test: [ "CMD", "pg_isready", "-U", "postgres", "-d", "nakama" ]
      interval: 3s
      timeout: 3s
      retries: 5
    image: postgres:12.2-alpine
    ports:
      - "5432:5432"
      - "8080:8080"
    volumes:
      - data:/var/lib/postgresql/data

  nakama:
    build: .
    container_name: game_backend
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
        /nakama/dlv --log --log-output=debugger --listen=:4000 --headless=true --api-version=2 exec nakama -- --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama
    depends_on:
      postgres:
        condition: service_healthy
    expose:
      - "7349"
      - "7350"
      - "7351"
    healthcheck:
      test: ["CMD", "/nakama/nakama", "healthcheck"]
      interval: 10s
      timeout: 5s
      retries: 5
    links:
      - "postgres:db"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
      - "2345:2345"
      - "4000:4000"
    restart: unless-stopped
    security_opt:
      - "seccomp:unconfined"
    stdin_open: true
    tty: true
volumes:
  data:

```

## Setting GoLand Configurations

1. Open GoLand Run/Debug Configurations by pressing **Add Configuration...** -> **Edit Configurations...**

![Opening GoLand Run/Debug Configurations]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_open_configurations.png" >}})

2. Add a Dockerfile configuration to run the nakama server:

![Adding Docker Configurations]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_add_docker_configurations.png" >}})

![Docker Configurations]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_config_docker.png" >}})

3. Add a Go Remote configuration and set the correct port:

![Adding Go Remote Configurations]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_add_remote_configurations.png" >}})

![Go Remote Configurations]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_config_remote.png" >}})

## Debugging and Setting Breakpoints

With the above changes in place, select the `Docker Configuration` and run it by clicking the start button.
Once Docker finishes the startup, run the Go Remote Configuration:

![Docker Running]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_docker_running.png" >}})

![Go Remote Running]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_remote_running.png" >}})

After the Nakama server is running you can set Go Function Breakpoints and debug from there.

### Breaking on an RPC

In the following example we have registered an RPC `SomeRpc` inside the `InitModule` function.

In order to add a breakpoint, press the red circle right next to the line number you want to add the breakpoint. 

![Setting first breakpoint]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_first_breakpoint.png" >}})

After doing this, a faded red circle will appear next to the function name, press that also.

![Setting Go Function breakpoint]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_second_breakpoint.png" >}})

{{< note "important" >}}
It is currently not possible to add breakpoints to lines of code that are not function signatures using the GoLand's breakpoint line toggle.
{{< /note >}}

We now need to trigger the RPC. We can do this either by calling it from a client or by visiting the [Nakama Console](/nakama/getting-started/console/) in a browser and using the API Explorer.

Once the RPC has been triggered, you should see that Goland successfully hits the breakpoint and you can now use the standard debugging tools (e.g. Variables, Locals, Step Into, Step Over etc).

![Goland Debbuger]({{< fingerprint_image "/images/pages/nakama/guides/server-framework/debugging-with-delve/goland/goland_delve_debugger_vars.png" >}})
