duanbei1903 2017-02-18 07:03
浏览 62
已采纳

$ GOPATH目录和磁盘空间

after a year or two developing with GO I had a look at my $GOPATH directory size and was surprised to see it was growing to a 4GB.

I understand that disk space is supposed (and it's not that much on this 128GB laptop SSD) to be cheap but still.

So my questions is, is there some good practice to manage the size $GOPATH directory ?

Would restarting from scratch would be a good idea? (although could be very much time consuming)

  • 写回答

1条回答 默认 最新

  • douping1825 2017-02-18 11:54
    关注

    Your statement, that deleting the GOPATH would be time consuming, sounds like you are managing the dependencies of your Go projects with plain go get .... In my environment I do two things to make the GOPATH ephemeral.

    1. Don't use plain go get for dependency management. Go 1.6 introduced the /vendor directory. Together with a dependency management tool like Glide every dependency for a certain project lies withing the project directory.

      1. This means, if don't need a dependency anymore you can wipe the vendor directory of the project and download the dependencies again. Therefore you only have dependencies on your disk, which you actually need.

      2. Also, if you stop working on a project and delete it from your disk, the dependencies also get deleted.

    2. You can specify multiple paths in the GOPATH. Like the PATH environment variable you can split them by a colon. The interesting thing is, that Go uses the first path for downloading projects. On my machine the GOPATH looks like $HOME/.gopath:$HOME/projects. So if you put all your actual projects into the second directory, you will have an clear separation between your projects and dependencies. Thus you could wipe the first directory from time to time, but don't need to fear that you have to clone every of your projects, again.

    These two things don't help to reduce the disk usage of your Go projects and their dependencies, but you get a better overview whats actually needed and makes you able to delete the dependency directory whenever you like.

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

报告相同问题?

悬赏问题

  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信