浮名浮利,虚苦劳神。叹隙中驹,石中火,梦中身。——苏轼《行香子·述怀》

grpc初识

使用grpc 内置的 protobuf 协议,其 DSL 语法 可清晰定义服务间通信的数据结构。 可参考:gRPC Go: Beyond the basics 编写好.proto 文件后可以使用Makefile 进行构建 1 2 3 4 5 build: # 一定要注意 Makefile 中的缩进,否则 make build 可能报错 Nothing to be done for build # protoc 命令前边是一个 Tab,不是四个或八个空格 # grpc:后面最好跟绝对路径 protoc -I. --go_out=plugins=grpc:$(GOPATH)/src/shippy/consignment-service proto/co...

阅读更多

ubuntu1804 设置开机启动脚本

在Ubuntu 1804 中使用/etc/rc.local 1、systemd默认读取/etc/systemd/system下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。一般系统安装完/lib/systemd/system/下会有rc-local.service文件,即我们需要的配置文件。 可以复制一份 不去动/lib/systemd/system/下面的文件 cp /lib/systemd/system/rc-local.service /etc/systemd/system/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 # SPDX-L...

阅读更多

在使用golang时常见的错误

1 在循环迭代器变量上使用goroutines 错误的写法: 1 2 3 4 5 for _, val := range values { go func() { fmt.Println(val) }() } 上面的for循环可能无法达到您的预期,因为它们的val变量实际上是一个单独的变量,它接受每个slice元素的值。 因为闭包只绑定到那个变量,所以很有可能当你运行这个代码时,你会看到每次迭代打印的最后一个元素而不是序列中的每个值,因为goroutines可能不会开始执行,直到 循环之后。 编写闭包循环正确的写法应该是: 1 2 3 4 5 for _, val := range values { go func(val interface{}) { f...

阅读更多

Golang 数据类型的转换

1、基本数据类型之间的转换 1.1、string到int int,err:=strconv.Atoi(string) 1.2、string到int64 int64, err := strconv.ParseInt(string, 10, 64) 1.3、int到string string:=strconv.Itoa(int) 1.4、int64到string string:=strconv.FormatInt(int64,10) 1.5、字符串到float32/float64 float32, err = ParseFloat(string, 32) float64,err = ParseFloat(string,64) 1.6、int64转int int:=...

阅读更多

Welcome

If you see this page, that means you have setup your site. enjoy! :ghost: :ghost: :ghost: You may want to config the site or writing a post next. Please feel free to create an issue or send me email if you have any questions.

阅读更多