doupai8533 2017-11-06 20:35
浏览 61
已采纳

插入调试环境json属性VSCode

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?

  • 写回答

1条回答 默认 最新

  • doucan1979 2017-11-06 20:46
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)