插入调试env json propety VSCode

时间:2017-11-06 20:35:53

标签: json go visual-studio-code

我想配置go debug env json属性,如下面的

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

我试图将以下内容输入env但我收到错误

"configurations": [

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

        },

当我将DEV_PROP插入env对象时,我得到了很多错误,我试图使用配额而没有成功,任何想法?

1 个答案:

答案 0 :(得分:1)

你有这样的尝试吗?

{
    "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"
    },

如图所示http://techbrij.com/visual-studio-code-tasks-debugging

同样按惯例,环境变量应该都是UPPER_CASE,如https://stackoverflow.com/a/673940/6314736

所示

所以看起来应该是这样的:

{
    "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"
    }
}

此外,如果您想为开发环境单独启动,只需复制此对象并更改" name"属于你喜欢的任何东西。它应该在Configuration数组中。

修改 正如Adrian指出的那样,我对这个问题的回答是错误的。 正确的答案是使用反斜杠转义双引号。 "env":{ "DEV_PROP":"\"run\":\"app.sh\",\"server_port\":\"8081\",\"app_url\":\"http ://localhost:3000\"}" }

我已经测试过了,它运行正常。 Picture for proof