
golang
harryhare
这个作者很懒,什么都没留下…
展开
-
go 时间相关
https://studygolang.com/articles/8919转载 2018-05-17 10:20:27 · 490 阅读 · 0 评论 -
Goland 本地attach 调试和远程调试
local attach https://www.jetbrains.com/help/clion/attaching-to-local-process.htmlremote debug https://www.jetbrains.com/help/clion/remote-debug.html转载 2018-06-10 23:19:58 · 6535 阅读 · 3 评论 -
go 调用C
https://blog.youkuaiyun.com/zhuyunfei/article/details/71480290转载 2018-08-02 12:00:42 · 310 阅读 · 0 评论 -
go 的一个简单 http server 的例子
包括middle ware, MongoDB,和JSON API 部分的详细解析。 这个系列一共五篇,下面的链接是第一篇。 https://www.nicolasmerouze.com/build-web-framework-golang/转载 2018-08-19 18:03:23 · 1324 阅读 · 0 评论 -
mgo 备忘
选择列直接在 mongo client 中,这点比较好做:db.people.find({name: "harryhare"}, {name: 1, _id: 0}) // 这可能是少数的几个 需要参数多于1个的使用情景此功能对应mgo的select1var result []struct{ Text string `bson:"text"` }err := c.Find(nil)原创 2018-10-08 04:41:11 · 183 阅读 · 0 评论 -
一个例子明白go 的package
一个 project,三个 main 函数两个目录, 同一个 包名import 的是目录,调用时用包名相同名字的包,如果要在同一个文件中引用,可以重命名包(entry3)// entry3.gopackage mainimport ( "fmt" dir1 "dir1" dir2 "dir2")func main(){ fmt.Println原创 2018-11-09 14:50:11 · 4222 阅读 · 0 评论 -
RSA PKCS1(google play receipt 验证)
go rsa 说明https://blog.youkuaiyun.com/xz_studying/article/details/80314111私钥有两种格式,要用不同函数来解析:ParsePKCS1PrivateKeyParsePKCS8PrivateKey有 加密解密,签名验证两个套路:加密解密:公钥加密,私钥解密签名验证:私钥签名,公钥验证google play receipt...转载 2019-01-14 21:34:04 · 1427 阅读 · 1 评论 -
go url
fmt.Println(url.QueryEscape("https://www.test.com/test?query=猪")) fmt.Println(url.PathEscape("https://www.test.com/test?query=猪")) fmt.Println(url.ParseQuery("a=111&b=222")) fmt.Println(url.P...原创 2019-02-24 22:26:04 · 921 阅读 · 0 评论 -
golang base64
注意 base64.StdEncoding 和base64.URLEncoding 的区别package mainimport ( "encoding/base64" "fmt&原创 2019-03-03 12:21:32 · 1018 阅读 · 0 评论 -
md5 python/go
go前两段hash 的结果相同空的hash 结果并不为空,而是 d41d8cd98f00b204e9800998ecf8427esum 的作用比较奇怪1:其实只是把参数加到当前hash 值的前面作为结果输出,并不改变hash的状态。唯一参数不为空的情形是: 需要把每个hash块的值连起来.所以实际使用中几乎遇不到sum的参数不是nil的情况func test_hash(){ h:=...原创 2019-03-04 00:08:39 · 156 阅读 · 0 评论 -
go slice 的一个不当的用法
错误示例package mainimport "fmt"type MyStruct struct{ Value int}func main(){ ss:=[]MyStruct{ {Value:1}, {Value:2}, {Value:0}, } largest:=&ss[0] for _,s:=range ss{ if s.Value&amp原创 2019-03-17 15:17:38 · 339 阅读 · 0 评论 -
go 正则
概述一些例子https://www.cnblogs.com/golove/p/3269099.htmlhttps://golang.org/src/regexp/example_test.go一般正则有三块功能matchfind(find one,find all, find sub-match)replace (sub-match 的引用 )几点注意go 的正...原创 2019-03-17 21:06:08 · 1454 阅读 · 0 评论 -
golang 闭包的例子
package mainimport ( "fmt")func get_fun(x int)func(){ return func(){fmt.Println(x)}}func main() { f1:=get_fun(1) f2:=get_fun(2) f1() f2()}原创 2019-04-14 12:57:02 · 102 阅读 · 0 评论 -
go web socket
有两个可用库,下面是两个简单的例子web socket 似乎只是相当于在普通的http 协议中加入了一个升级协议的部分,gorilla/websocket 中显式的体现了这一步x/net/websocket 中则把这一步封装成 websocket.Handler(handler)github.com/gorilla/websocketpackage mainimport ( "...原创 2019-06-10 10:04:58 · 333 阅读 · 0 评论 -
go race 检测
go run xxx.go 后面加上 -race 参数就下面这样:$ go run -race race.go==================WARNING: DATA RACEWrite at 0x00c0000a2000 by goroutine 6: main.main.func2() /Users/unity/git/go_playground/src/rac...原创 2019-06-23 20:15:31 · 4817 阅读 · 0 评论 -
go http 请求
比较简单的方式有两个:(下面的代码是抄的) 1.http.post()/http.get()func httpPost() { resp, err := http.Post("http://www.01happy.com/demo/accept.php", &a转载 2018-06-10 09:06:39 · 1740 阅读 · 0 评论 -
go heap
https://golang.org/pkg/container/heap/// This example demonstrates an integer heap built using the heap interface.apackage mainimport ( "container/heap" "fmt")// An IntHeap is a min-...转载 2018-06-09 14:25:07 · 266 阅读 · 0 评论 -
go map slice 做参数
参考: https://www.cnblogs.com/snowInPluto/p/7477365.htmlfunc maptest1(m map[string]string){ m["1"]="111"}func maptest2(m *map[string]string){ (*m)["2"]=&quo原创 2018-05-17 10:37:47 · 831 阅读 · 0 评论 -
go 类型转换
https://www.linuxidc.com/Linux/2014-02/96095.htm和c++不同的地方在于指针是无法强制转换的,除非用unsafe 这篇中有个类型强转后,访问私有成员的例子func typeTest() { var x int=10 var px *int=&x fmt.Println(px) var y int3...原创 2018-05-17 11:18:55 · 1011 阅读 · 0 评论 -
go 备忘
http://www.jb51.net/article/56837.htm总结一下就是 make 仅用于在slice map chan new 用在struct make 指定长度,和reserve 的内存,返回slice map chan类型 new 返回指针原创 2018-05-17 11:33:32 · 203 阅读 · 0 评论 -
golang interface 和 reflect
占坑转载 2018-05-14 10:12:36 · 244 阅读 · 0 评论 -
go 调试
1.gdb https://studygolang.com/articles/2914 (没有看)2.ide https://blog.youkuaiyun.com/freshfox/article/details/78458621转载 2018-05-20 21:45:43 · 655 阅读 · 0 评论 -
go io
https://studygolang.com/articles/2073原创 2018-05-20 23:53:06 · 335 阅读 · 0 评论 -
golang routine context chan select
占位原创 2018-05-16 01:28:09 · 269 阅读 · 0 评论 -
golang 内存
占位转载 2018-05-16 01:29:28 · 383 阅读 · 0 评论 -
golang 异常处理
占位转载 2018-05-16 01:30:03 · 989 阅读 · 0 评论 -
golang http request 读两次body
方法是body重新赋值,bodyBytes, _ := ioutil.ReadAll(req.Body)req.Body.Close() // must closereq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))看了三个网页,都是这样做的: https://stackoverflow.com/questions/4...原创 2018-06-11 21:02:05 · 6540 阅读 · 2 评论 -
go convey
golang 的一个测试库: https://github.com/smartystreets/goconvey/wiki/Assertions转载 2018-06-12 07:52:39 · 1062 阅读 · 0 评论 -
go run build install test
1.run 和 build 只要设置好$GOPATH 就可以使用go run main.gogo build main.go在src 内,go build 不用加文件名2.testgo test -v packagenamego test -v filename1,filename2,filename3-v 显示测试的详细信息 ...原创 2018-06-05 14:14:08 · 601 阅读 · 0 评论 -
go interface
简单写了一个类似ReadCloser的东西 其实库函数中有一个ioutil.NopCloser() 不过为了知道interface怎么用package mainimport ( "fmt" "io" "strings" "io/i原创 2018-06-22 20:35:29 · 172 阅读 · 0 评论 -
golang LimitReader TeeReader Buffer例子
用到buffer的地方要加&package mainimport ( "strings" "io" "bytes" "fmt" "io/ioutil")func ma原创 2018-06-23 09:33:41 · 1490 阅读 · 0 评论 -
向AWS S3 上传文件
目的是为了要上传大一些的文件,如果中间网络出现问题,后面可以有断点续传类似的功能。1.官方S3使用的例子 https://github.com/aws/aws-sdk-go/blob/master/service/s3/examples_test.go非官方mulitpart上传的例子 https://github.com/apoorvam/aws-s3-multipart-uploa...原创 2018-06-15 22:36:09 · 22529 阅读 · 1 评论 -
go convey 报错
报错Convey operation made without context on goroutine stack.解决似乎是 go 升级到 1.12 后,goconvey 没有升级。所以,go get -u github.com/smartystreets/goconvey原创 2019-07-31 15:56:51 · 1784 阅读 · 0 评论