分类 默认分类 下的文章

问题: Golang IDE在按下f8进行步进调试时, 发现一直显示connected, 卡住无法往下走.
怀疑: 最近有更新了go版本,怀疑可能和这个有关.
解决方案: 试了几个网上办法.发现这个办法管用,而且很简单, 30s搞定.
大体原因是delve版本太低可能不兼容.(delve是专门用于go调式的工具) 具体操作如下

  1. Install the latest delve (mac平台用brew命令安装即可很快,命令: brew install delve)
  2. then in IntelliJ: Help → Edit Custom Properties...
    Add the following as a new line
    dlv.path=/usr/local/bin/dlv
  3. Save, close and restart the IDE

这套下来30s, 遇到类似的情况, 强烈建议试试!

    /**
     * unset多维数组中指定的key
     * @param $arr
     * @param $name "a[b]" or "1[1]"
     * @return bool
     */
    public static function unsetByIndex(&$array, $name)
    {
        $matches = [];
        if(!preg_match_all('/\[?([\w-]+)\]?/', $name, $matches)) {
            return false;
        }
        if(!empty($matches) && !empty($matches[1])) {
            $indexToRemove = $matches[1];
            $lastIndex = array_pop($indexToRemove);
            foreach ($indexToRemove as $index) {
                if (isset($array[$index]) && is_array($array[$index])) {
                    $array = &$array[$index];
                } else {
                    // Element or index doesn't exist
                    return false;
                }
            }
            if (isset($array[$lastIndex])) {
                unset($array[$lastIndex]);
                return true;
            }
        }
        return false;
    }
测试demo
$multiArray = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

unsetByIndex($multiArray, '1[1]');
print_r($multiArray);
//结果
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [2] => 6
        )

    [2] => Array
        (
            [0] => 7
            [1] => 8
            [2] => 9
        )

)

docker decktop开始收费了,不过docker还是免费开源的. docker decktop做角色其实就是 虚拟机 + linux系统 + docker; 因为docker是利用linux内核来管理资源, 所以你的mac没法直接跑docker(mac系统是没有linux内核的). 因为docker还是免费开源,你自己搭建一个linux环境也是能直接使用docker的. 调研多种方案给出最推荐的方式.避免你选择困难症.
  1. 使用社区版
    推荐.除了没有像docker那样图形管理界面的能力,但其他都一样,要用时敲下命令是一样的.和docker一样,只要安装下安装包.
    社区版本下载地址
  2. 还有个不错的替代者: https://github.com/abiosoft/colima

注意: docker卸载后所有容器和镜像都会没掉,所以卸载前一定要记得备份
备份也很简单,步骤如下:

  1. Open Terminal on your Mac.
  2. In the Terminal window, type the following command to list all your Docker images:

    docker images
  3. Note the image ID or names of the images you want to keep.
  4. Type the following command to save the images to a .tar file:

    docker save -o /path/to/save/myimage.tar myimage

    Replace /path/to/save/ with the path to the directory where you want to save the .tar file, and myimage with the image name or ID you noted in step 3.

  5. Repeat step 4 for each image you want to save.
  6. Once you have saved all the images, you can uninstall Docker Desktop as you normally would.
  7. When you reinstall Docker Desktop, you can restore the saved images by typing the following commands:

    docker load -i /path/to/save/myimage.tar

    Replace /path/to/save/ with the path to the directory where you saved the .tar file, and myimage with the image name or ID you want to restore.
    Repeat this command for each saved image.