golang技巧,go技巧
1)centos安装golang
yum -y install golang
// 查看环境
go env
下载https://studygolang.com/dl
centos7安装新版golang, win10配置环境变量,GOPATH
默认放在C:\User\用户名\go下面
; 配置GOROOT
,也就是go的安装目录。go env 可看配置路径。配置代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
初始化文件夹go mod init glua.com
然后安装第三方库go get github.com/yuin/gopher-lua
如果是别人的项目,下载后,要安装库go install
`
2)怎么学习golang:最好的go视频学习网站
最全:https://github.com/talkgo/read, 通过例子学习,中文 https://gobyexample-cn.github.io/
https://github.com/quii/learn-go-with-tests
https://studygolang.gitbook.io/learn-go-with-tests/
https://github.com/ardanlabs/gotraining-studyguide
https://www.runoob.com/go/go-tutorial.html
3)其他工具安装:gcc安装, skynet安装,
4)以前go笔记https://www.xigk.com/blog/index.php/archives/412/
5)go bbs:https://gitee.com/mlogclub/bbs-go
6)go server:https://github.com/Golangltd/LollipopGo ,最好用golang做游戏框架,用lua脚本写游戏逻辑。
7)go安装第三方库:go get -u xxx
8)go mod使用。 初始化go mod init 模块名,这样才能go build main.go
9)Golang标准库文档 https://studygolang.com/pkgdoc
10)创建项目:go mod init xigk.com/cp
,然后新建main.go文件
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
11)配置开机启动
进入以下目录cd /etc/init.d/
;
新建脚本文件go.sh,内容如下
#!/bin/bash
cd /www/wwwroot/www.xigk.com/
nohup ./gocp1 &
cd /www/wwwroot/gocp/
nohup ./gocp2 &
增加go.sh权限
chmod +x go.sh
//加入chkconfig命令进行管理
chkconfig --add go.sh
//设置该脚本为开机自运行
chkconfig go.sh on
//移除
chkconfig go.sh off
chkconfig --del go.sh
12)