Go
si_ma_tong_ming
谁把谁的明媚尽收眼底,
谁把谁的难过感同身受。。。
展开
-
GO的路径问题
在go语言中,import导入的时候导入的是路径,而在使用的时候使用的是package名 例如: test.go:package t_unit//import "fmt"type Sort interface { Min(a int) bool}//func init() {// fmt.Println("aaassadas")//}root.go:package mai原创 2017-09-28 17:44:20 · 928 阅读 · 0 评论 -
negroni
一.简介negroni是一个web中间件,方便使用net/http的库;它实现了http.Handle接口,兼容http.Handle.获取方式:go get github.com/urfave/negroninegroni的主要的结构:type Negroni struct { middleware middleware //节点结构 handlers []Handl原创 2018-01-25 16:54:16 · 927 阅读 · 0 评论 -
一致性哈希库:stathat.com/c/consistent
应用场景: 假如你有 N 个 cache 服务器,那么你可能会使用hash(object)%N将对象 object均匀映射到 N 个 cache上,这样可以运行,但是当服务器宕掉或者添加服务器时,映射规则都会改变,所有的cache都会失效。所以需要使用一致性哈希算法避免这种情况。关于一致性哈希算法可以参考:http://blog.csdn.net/cywosp/article/deta原创 2018-01-17 17:37:46 · 1021 阅读 · 0 评论 -
fatal error: concurrent map read and map write
一.问题map是线程不安全的,即使并发读写没有冲突也会报错(fatal error: concurrent map read and map write):func main() { m := make(map[int]int) go func() { for { _ = m[1] } }() go func() { for { m[2] = 2 }原创 2018-01-16 18:04:31 · 6839 阅读 · 0 评论 -
first path segment in URL cannot contain colon
一:问题func main(){ url,err:= url.Parse("127.0.0.1:8080") if err!=nil{ fmt.Println(err) } fmt.Println(url.Host,url.Port())}使用url.Parse()解析host是ip的url时(eg:127.0.0.1:8080),出现:first pa原创 2017-11-15 14:00:23 · 37155 阅读 · 0 评论 -
xorm的基本使用
中文文档:http://www.xorm.io/docs/ github地址:https://github.com/go-xorm/xorm 安装:go get github.com/go-xorm/xorm一.创建连接原创 2017-10-04 23:38:31 · 14993 阅读 · 0 评论 -
安装xorm工具出现第三方工具依赖
一.问题 1).当输入go get github.com/go-xorm/cmd/xorm 时出现: package golang.org/x/net/context: unrecognized import path “golang.org/x/net/context” (https fetch: Get https://golang.org/x/net/context?go-get=1: d原创 2017-10-05 12:56:55 · 1374 阅读 · 0 评论 -
Gin框架初识
关于Gin的具体说明与源码:https://github.com/gin-gonic/gin一.安装 命令行输入:go get github.com/gin-gonic/gin 安装位置:go的环境变量中配置的全局的lib目录二:基本应用1. GET 1)gin.Context中的Query方法:get的URL传参func getQuery(context *gin.Context){原创 2017-10-04 17:35:48 · 4267 阅读 · 0 评论 -
go中结构体与json的格式转换
基于简单结构体的处理,结构体的嵌套类似type User struct { UserName string PassWord string }1)结构体->json user := User{ UserName: "tyming", PassWord: "1234567890",//这里逗号不能少 } //json.Marsha原创 2017-10-09 13:24:37 · 10876 阅读 · 0 评论 -
Go的并发
首先并行!=并发,并发是逻辑上的并行. 例如:多个程序在单核处理器上运行,每个程序只能在对应的时间片上运行,因为时间片很短,看起来就像是并行. 一.go语言级别的线程goroutine goroutine是Go语言中的轻量级线程实现.它是一个普通的函数,只需使用保留字 go 作为开头。 例如:两个goroutine打印1-10//这个程序是不会输出的,因为go还没执行完成,m原创 2017-09-29 14:51:55 · 969 阅读 · 1 评论 -
JWT实现基于token的鉴权
一.介绍 1.JSON Web Token,简称JWT,本质是一个token,是一种紧凑的URL安全方法,用于在网络通信的双方之间传递。 2.一般放在HTTP的headers 参数里面的authorization里面,值的前面加Bearer关键字和空格。 3.主要用于身份认证和信息交换 4.由三部分组成,用英文句点连接(.),例如:xxxxxx.yyyyyy.zzzzzz二.J原创 2018-01-25 17:59:15 · 4737 阅读 · 0 评论