终端使用shadowsocks

写这篇文章的目的,很简单,解决golang dep安装依赖包被墙无法正常开发的问题,做个记录。如果你也遇到这类问题,就请往下看。

NOTE: 开发环境操作系统为OSX

首先,你要有个自己shadowsocks账号;如果你还没有,以下是我个人的意见:

  • 购买阿里云香港节点(三年800人民币不到,目前为止响应速度还不错)
  • docker工具部署shadowsocks docker-shadowsocks

好了,现在你已经准备好了一切,但是你在golang项目运行dep ensure时不一定如意:

接下来,我们要解决的问题是在终端也能翻墙!

安装 polipo 工具

brew install polipo

polipo程序开机自启动

vim /usr/local/opt/polipo/homebrew.mxcl.polipo.plist

需要给polipo命令加上命令行参数 socksParentProxy=localhost:1080, 完整配置如下:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>homebrew.mxcl.polipo</string>
      <key>RunAtLoad</key>
      <true/>
      <key>KeepAlive</key>
      <true/>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/opt/polipo/bin/polipo</string>
        <string>socksParentProxy=localhost:1080</string>
      </array>
    </dict>
  </plist>

紧接着执行以下命令:

ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist

polipo 启动

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist

设置别名

bash中有一个很好的东西,就是别名alias. Linux用户修改~/.bashrc,Mac用户修改~/.bash_profile文件或者~/.zshrc,增加如下设置:

alias proxy="export http_proxy=http://localhost:8123;export https_proxy=http://localhost:8123" //会话全局设置
alias unproxy="unset http_proxy" //撤销当前会话的http_proxy代理
source ~/.zshrc

接下来,你只要运行proxy就可以全局代理了,取消代理使用unproxy

如果你到这还遇到问题,那请参考以下资料:

猜你喜欢

转载自my.oschina.net/tygogo/blog/1627057