使用Vim编辑器开发Go简单入门

今天是一次做Go的笔记,一开始直接打开Github上的Go项目然后跑到Wiki位置,然后作者列出了一堆学习Go的资料,这里我
以第一个学习资料https://tour.golang.org/作为Go学习到入门。然后为了训练我的终端运用
能力还有Vim下的编码能力这里我使用到了tmuxVim编辑器,然后之前已经在VIM里面安装了Vim-go插件了,所以在之前
的Go项目文件目录下可以直接使用命令模式使用:Go来执行相应的操作。如果项目报错都话你可能是没有按照
Vim-go的要求现在项目里面执行:GoInstallBinaries.

You will also need to install all the necessary binaries. vim-go makes it easy to install all of them by providing a command, :GoInstallBinaries, which will go get all the required binaries.

但是由于但由于 go 的代码很多在 github 和 golang.org 上,涉及到墙的问题。自动安装可能会失败。当然你有梯子的话除外;

我们可以手工安装,进入到GOPATH的SRC目录下,运行命令git clone https://github.com/golang/tools golang.org/x/tools,再接着上一步:GoInstallBinaries即可

我的解决方式是先让终端邹代理,至于如何让终端走代理呢,无非就是

export http_proxy=http://127.0.0.1:12333
export http_proxy=https://127.0.0.1:12333

然后在通过命令打开vim,然后再:GoInstallBinaries,这样子就能下载Go所需要的文件了

最后出现如图所示:

项目一

package main

import (
	"fmt"
	"math/rand"
)

func main() {
	fmt.Println("My favorite number is", rand.Intn(10))
}

然后在Vim下面执行:Go Run即可输出

My favorite number is 1

项目二 Imports

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Printf("Now you have %g problems.\n", math.Sqrt(7))
}

输出

Now you have 2.6457513110645907 problems.

项目三 Exported names

In Go, a name is exported if it begins with a capital letter. For example, Pizza is an exported name, as is Pi, which is exported from the math package.

pizza and pi do not start with a capital letter, so they are not exported.

When importing a package, you can refer only to its exported names. Any “unexported” names are not accessible from outside the package.

Run the code. Notice the error message.

To fix the error,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值