1

I want to configure go debug env json properties like following

DEV_PROP=
'{
 "run": "app.sh",  
 "server_port": "8081",
 "app_url":"http://localhost:3000"
}'

Ive tried to enter the following to the env but I got error

"configurations": [

    {
        "name": "Launch",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "remotePath": "",
        "port": 2345,
        "host": "127.0.0.1",
        "program": "${fileDirname}",
        "env": {

        },

when I insert the DEV_PROP to the env object I got lots of error, ive tried to play with quotas without success, any idea?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130

1 Answers1

1

Did you try this way?

{
    "name": "Launch",
    "type": "go",
    "request": "launch",
    "mode": "debug",
    "remotePath": "",
    "port": 2345,
    "host": "127.0.0.1",
    "program": "${fileDirname}",
    "env": {
        "run": "app.sh",  
        "server_port": "8081",
        "app_url":"http://localhost:3000"
    },

As shown here http://techbrij.com/visual-studio-code-tasks-debugging

Also by convention environment variables should be all UPPER_CASE as shown here https://stackoverflow.com/a/673940/6314736

So it should look like that:

{
    "name": "Launch",
    "type": "go",
    "request": "launch",
    "mode": "debug",
    "remotePath": "",
    "port": 2345,
    "host": "127.0.0.1",
    "program": "${fileDirname}",
    "env": {
        "RUN": "app.sh",  
        "SERVER_PORT": "8081",
        "APP_URL":"http://localhost:3000"
    }
}

Also if you want to have separate launch for dev environment just copy this object and change "name" property to whatever you like. It should be in Configuration array.

EDIT As Adrian pointed out, my answer to this question was wrong. The correct answer is to escape double quotes with backslashes. "env":{ "DEV_PROP":"\"run\":\"app.sh\",\"server_port\":\"8081\",\"app_url\":\"http ://localhost:3000\"}" }

I've tested it and it works fine. Picture for proof

H4xorPL
  • 320
  • 3
  • 11
  • Not 100% sure but judging by the way the question is written, they want a single environment variable `DEV_PROP` whose value is the JSON they gave. – Adrian Nov 06 '17 at 21:17
  • oh yeah, you are probably right. Then maybe escape quotes with backslashes `"DEV_PROP":" { \"run\": \"app.sh\", \"server_port\": \"8081\", \"app_url\":\"http://localhost:3000\" }"` – H4xorPL Nov 06 '17 at 22:54