摘要: 使用grpc双向模式,可以实现客户端随时发送消息给服务端,服务端也可以随时发送消息到客户端,不再是一问一答的模式。 grpc_stream/hellowoldstream/helloworldstream.proto protoc --go_out=plugins=grpc:. helloworld 阅读全文
posted @ 2019-11-01 12:12 追逐~~~ 阅读(1210) 评论(0) 推荐(0) 编辑
摘要: 当我们服务越来越多,如果服务配置了弹性伸缩,或者当服务不可用时,我们需要随时动态掌握可以使用的服务数量,并向可提供响应的服务发送请求。这时我们需要服务发现功能,当新增服务时,服务可以自动向consul注册,客户端直接向consul发送请求,获取可用服务的地址和端口;当服务不可用时,动态的更新cons 阅读全文
posted @ 2019-09-05 09:18 追逐~~~ 阅读(12053) 评论(0) 推荐(0) 编辑
摘要: 当我们想杀死一个进程及其所创建的所有子进程,我们可以使用 linux 命令 kill -- -pid 执行 tail -f ./text.log| grep -a "5t6hwhu1" >../a330fec0-f946-5e47-1be3-5c42ef040c78.tmp 会发现生成了两个进程,一 阅读全文
posted @ 2019-08-19 12:45 追逐~~~ 阅读(4565) 评论(0) 推荐(0) 编辑
摘要: 1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 "net" 7 ) 8 9 func externalIP() (net.IP, error) { 10 ifaces, err := net.Interfaces() 11 if err != nil { 12 retu... 阅读全文
posted @ 2019-08-05 11:23 追逐~~~ 阅读(18789) 评论(0) 推荐(1) 编辑
摘要: 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "strconv" 7 "time" 8 9 "github.com/hpcloud/tail" 10 ) 11 12 func main() { 13 // 新启动一个协程一直往文件中写入 14 go writeSteam()... 阅读全文
posted @ 2019-07-10 11:54 追逐~~~ 阅读(809) 评论(0) 推荐(0) 编辑
摘要: 运行 go run ./websocket.go ,将websocket.html在浏览器中运行。 阅读全文
posted @ 2019-07-01 15:00 追逐~~~ 阅读(819) 评论(1) 推荐(0) 编辑
摘要: golang使用viper包解析配置文件 配置文件 阅读全文
posted @ 2019-05-24 19:11 追逐~~~ 阅读(5527) 评论(0) 推荐(0) 编辑
摘要: package main import ( "bytes" "crypto/cipher" "encoding/base64" "errors" "fmt" "strconv" "golang.org/x/crypto/blowfish" ) func main() { key := "PPpn7ugdcTa4DTUdqSkx... 阅读全文
posted @ 2019-05-13 09:51 追逐~~~ 阅读(1542) 评论(0) 推荐(0) 编辑
摘要: golang float精度有时会不准确 如上代码,我们预期得到的结果是1020,而实际得到的结果是1019.9999999999999 调用Float2Float()即可解决精度问题。 阅读全文
posted @ 2019-05-13 09:16 追逐~~~ 阅读(6675) 评论(0) 推荐(0) 编辑
摘要: zerolog是一个golang的高性能包,简单易用 阅读全文
posted @ 2019-04-28 15:28 追逐~~~ 阅读(2565) 评论(0) 推荐(0) 编辑