Golang的基础语法基本学完了,准备搞个项目练练手,试着用下beego框架,安装出现如下问题
[root@localhost /]# vi /etc/profile # 关于go的基本配置 export GOROOT=/usr/local/go export GOBIN=$GOROOT/bin export GOPATH=/mnt/hgfs/www/GoCode/ export PATH=$PATH:$GOBIN:/usr/local/php/bin/pecl:/usr/local/mongodb/bin [root@localhost /]# go get github.com/astaxie/beego # cd .; git clone https://github.com/astaxie/beego /mnt/hgfs/www/GoCode/src/github.com/astaxie/beego Initialized empty Git repository in /mnt/hgfs/www/GoCode/src/github.com/astaxie/beego/.git/ error: while accessing https://github.com/astaxie/beego/info/refs fatal: HTTP request failed package github.com/astaxie/beego: exit status 128
关于这个问题,网上一直搜不到非常好的解决办法,甚至有人直接下载源码安装,非常不优雅
既然https用不了,改成ssh协议应该没问题,试下
[root@localhost /]# git clone git@github.com:astaxie/beego /mnt/hgfs/www/GoCode/src/github.com/astaxie/beego Initialized empty Git repository in /mnt/hgfs/www/GoCode/src/github.com/astaxie/beego/.git/ The authenticity of host 'github.com (52.74.223.119)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? y Please type 'yes' or 'no': yes Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. Permission denied (publickey). fatal: The remote end hung up unexpectedly
按下面方法来解决,先生成一个ssh key,将其添加到github账号ssh-key-lists里面,git config的其他设置不具体说了
[root@localhost ~]# ssh-keygen -t rsa [root@localhost ~]# vi /root/.ssh/id_rsa.pub
再试下安装,ok,同理安装 bee 工具
[root@localhost ~]# git clone git@github.com:beego/bee /mnt/hgfs/www/GoCode/src/github.com/beego/bee [root@localhost ~]# go install github.com/astaxie/beego/ # github.com/astaxie/beego/utils /mnt/hgfs/www/GoCode/src/github.com/astaxie/beego/utils/utils.go:13: undefined: strings.Compare [root@localhost ~]# go version go version go1.4.1 linux/amd64
通过这种方式安装的 beego,缺失很多 packages,不是太完美
我本地go版本太低了,升级到1.7后就不报错了
重装后执行go相关命令报如下错误,说明环境变量未生效,试下 source /etc/profile
[root@localhost src]# go build imports runtime: C source files not allowed when not using cgo or SWIG: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_linux.c mfixalloc.c mgc0.c mheap.c msize.c os_linux.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c vdso_linux_amd64.c
我本地环境比较奇葩,我直接把/usr/local/go 文件夹删掉重装了
[root@localhost src]# wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz [root@localhost src]# tar -zxf go1.7.3.linux-amd64.tar.gz -C /usr/local/
bee使用
[root@localhost src]# bee new hello [root@localhost src]# bee run hello
我本地用虚拟机,修改下防火墙配置,开放8080端口
# 添加 -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT [root@localhost ~]# vi /etc/sysconfig/iptables [root@localhost ~]# service iptables restart
再通过浏览器访问,这样beego使用算是入门了
花了好几个小时才解决的问题,值得记录下,遂有了此博客