1、安装:
下载:https://www.golangtc.com/download,例如Ubuntu64位,就下载go1.9.2.linux-amd64.tar.gz
解压之后,将go/bin添加到PATH
2、hello word
创建源代码文件hello-word.go,写入
package main import "fmt" func main(){ fmt.Println("this is fuck hello word!") }
然后运行go run hello-word.go即可看到运行结果。
也可以运行go build hello-word.go得到名为hello-word的二进制文件,执行./hello-word也可以看到运行结果
3、编写Makefile
hello: hello-word.go @echo "fuck you" /home/thinking/Documents/go/bin/go build hello-word.go
4、解决go can't load package: package github.com
用go get,或者go install
具体参考http://wiki.jikexueyuan.com/project/go-command-tutorial/0.3.html
例如,你得到了如下错误
can't load package: package github.com/hyperledger/fabric/core/chaincode/shim: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of: /home/yong/Downloads/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT) /home/yong/Downloads/go/bin/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH) find: ‘/home/yong/Downloads/go/bin/src/github.com/hyperledger/fabric/core/chaincode/shim’: No such file or directory
配置好$GOPATH和$GOROOT两个环境变量
然后在任意位置执行
go get github.com/hyperledger/fabric/tree/release-1.1/core/chaincode/shim
等待一段时间你就会在$GOPATH或$GOROOT下找到所需要的库