最近开始学习golang开发,一直以来从事PHP开发,接触了golang后便被她深深的吸引了。
gofmt带来了代码一致性,解决了困扰开发多年的代码风格不统一的问题,这是给人的最直观感受。
语法的简洁性,以及自定义类型的灵活性。语言本身只定义了基本数据类型结构,例如int, string, array, slice, map,其他可由struct来自行实现。
goroutine带来的飞跃性好处,是其他语言所没有或没那么容易实现的。它可由以前串行执行的方法改为并行执行,想想都叫人愉快 ^_^, 充分利用了机器的多核性能。
编译型语言带来的好处不言而喻,以及跨平台特性。真正实现了
Build Once, Run anywhere
。方便的文档以及可分享的playground。
在使用vscode开发go程序的时候,需要安装相关的go插件来提升开发效率。不过总是安装失败,提示包没找到等错误。即使我用了shadowsocks也是一样,通过Google一番,有两种解决方案。
这是安装插件时候的报错信息
go get -u -t -v github.com/golang/lint/golint
github.com/golang/lint (download)
Fetching https://golang.org/x/tools/go/gcexportdata?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 172.217.10.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?go-get=1: dial tcp 172.217.10.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
第一种就是使用其他软件将shadowsocks代理转换为http代理。
第二种就是在github上手动下载相关的包,然后编译安装。
我用了第一种,因为比较懒,不想以后安装其他插件的时候也要一个个手动。
下面说下解决步骤:
brew install polipo
安装polipo, 一种将其他代理转换为http代理的程序编辑polipo的配置文件
/etc/polipo/config
socksParentProxy = "127.0.0.1:1080" socksProxyType = socks5 proxyAddress = "::0" proxyPort = 8123
启动polipo服务
polipo -c /etc/polipo/config
设置终端临时代理, 可能需要在vscode的终端设置.
export http_proxy="http://127.0.0.1:8123" export https_proxy="http://127.0.0.1:8123"
- 测试HTTP代理
curl --proxy http://127.0.0.1:8123 https://www.google.com
, 如果成功输出内容就可以开始安装VSCode插件了
以上只是我的解决方案,下面是一些下该方案和其他方案的链接
第二种是需要手动下载包的, 可做参考
第三种,终端直接设置第三方代理工具,goproxy.io提供了很好的解决方案,具体请参考https://goproxy.io/zh/