golang

发布时间:2019-02-27 14:29:05 阅读:774次

http://c.biancheng.net/golang/intro/

https://www.idreamschool.com/golang/beego/285.html

go专家编程

https://www.bookstack.cn/read/GoExpertProgramming/README.md

操作mysql

https://www.cnblogs.com/flying1819/articles/8832613.html

go下载

https://studygolang.com/dl

https://www.cnblogs.com/unqiang/p/6594451.html

https://www.jianshu.com/p/b2222fc04f47

go web开发
https://astaxie.gitbooks.io/build-web-application-with-golang/zh/03.2.html

yum install golang
redis go
https://github.com/gomodule/redigo
https://blog.csdn.net/han0373/article/details/80611111
package main
 
import (
 "github.com/garyburd/redigo/redis"
 "fmt"
 "time"
)
 
func main() {
 conn, err := redis.Dial("tcp",
 "127.0.0.1:6379",
 redis.DialDatabase(1), //DialOption参数可以配置选择数据库、连接密码等
 redis.DialPassword("password"))
 if err != nil {
 fmt.Println("Connect to redis failed ,cause by >>>", err)
 return
 }
 defer conn.Close()
 
 //如果db有密码,可以设置
 //if _,err := conn.Do("AUTH","password");err !=nil{
 //	fmt.Println("connect db by pwd failed >>>",err)
 //}
 
 //写入值{"test-Key":"test-Value"}
 _, err = conn.Do("SET", "test-Key", "test-Value", "EX", "5")
 if err != nil {
 fmt.Println("redis set value failed >>>", err)
 }
 
 time.Sleep(10 * time.Second)
 //检查是否存在key值
 exists, err := redis.Bool(conn.Do("EXISTS", "test-Key"))
 if err != nil {
 fmt.Println("illegal exception")
 }
 fmt.Printf("exists or not: %v \n", exists)
 
 //read value
 v, err := redis.String(conn.Do("GET", "test-Key"))
 if err != nil {
 fmt.Println("redis get value failed >>>", err)
 }
 fmt.Println("get value: ", v)
 
 //del kv
 _, err = conn.Do("DEL", "test-Key")
 if err != nil {
 fmt.Println("redis delelte value failed >>>", err)
 }
}
beego框架
https://beego.me/
https://beego.me/quickstart




$ go get -u github.com/astaxie/beego
$ go get -u github.com/beego/bee
export http_proxy="http://192.168.2.234:808/"
export https_proxy="https://192.168.2.234:808/"
yum install go
yum install golang
go version
go get -u github.com/astaxie/beego
go get -u github.com/beego/bee
echo 'export GOPATH="$HOME/go"' >> ~/.profile
echo 'export PATH="$GOPATH/bin:$PATH"' >> ~/.profile
exec $SHELL
source ~/.profile
export
go version
echo $PATH
echo $GOPATH
cd $GOPATH/src
bee new hello
cd hello
bee run

go env

在centOS下,安装go的环境,如下:
下载压缩包,wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
解压该文件,由于默认的go路径,在/usr/local下, 所以用如下命令,解压创建/usr/local/go
tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gz 
配置环境变量,vim /etc/profile下,添加对应的goroot和gopath的配置环境
export GOROOT=/usr/local/go
export GOPATH=/app/gopath        之后,source /etc/profile 使得其配置文件有效.
检查go的版本,$ go version 
在go的开发路径下,我的demo是写在/app/gopath/src/hello下面的,编写helloworld.go的例子。  具体如下:
package main
import "fmt" 
func main() { 
    fmt.Printf("Hello, world.\n") 

之后,go bulid helloworld.go,生成了helloworld的文件;  或者直接执行 go run helloworld.go 直接可以看到结果
./helloworld 直接执行,输出了 Hello world

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:golang 出自老鄢博客 | 欢迎分享