I made some Go scripts that require user input fmt.Scanln(&fileName) during the execution. When I use the Go debugger built into VSCode which is the launch type, it works but there is no way to enter any prompts when your exeuctable asks for a input. With other programming languages like NodeJS and PHP, there is way to run the scripts in “debugging mode” where it will run the code but before it executes the code, it will wait to attach to a debugger on your system and then execute the code. This has always allowed me to use the terminal for inputs in the executable.

For example to do this in NodeJS, you will use node --inspect-brk=0.0.0.0 main.js instead of node main.js and then run the debugger in VSCode to attach it to the executing script. Is there a way to do this with Go? Do I need to set something up to achieve this?

I am on Linux Mint and cannot find any commands to run go run . but to wait for a debugger to attach to the executable before executing.

  • @bilagaana
    link
    25 months ago

    If you modify your ./vs code/launch.json to include the "console": "external terminal" parameter, it will accomplish what you are looking for.

    
    {
    
        // Use IntelliSense to learn about possible attributes.
    
        // Hover to view descriptions of existing attributes.
    
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    
        "version": "0.2.0",
    
        "configurations": [
    
            {
    
                "name": "Launch file",
    
                "type": "go",
    
                "request": "launch",
    
                "mode": "debug",
    
                "program": "${workspaceFolder}/main.go",
    
                "console": "externalTerminal",
    
            },
    
            
    
        
    
        ]
    
    }
    
    
    • @trymeoutOP
      link
      English
      15 months ago

      "console": "integratedTerminal" also works! Thank you?

      Do you have a simple setup guide on how to get debugging to work with Go inside a docker container?