Skip to content

huyinghuan/beter4go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

beter4go

English

写go的一些经验

gzip

如果你的服务依赖其他的服务接口,在条件允许的时候,建议 依赖服务的接口 nginx层关闭gzip。

因为对应开启了gzip的接口,ioutil.ReadAll读取内容时,会调用gzip进行数据解压,在高qps的时候,会消耗比较高的io

如果不能修改nginx层,那么可以 通过设置header 来 Accept-Encoding: 0 来禁止nginx自动gzip。 【标准http服务器都支持。】 具体协议见: https://tools.ietf.org/html/rfc2616#section-14.2

json

建议使用 github.com/json-iterator/go 代替原生 json 进行json序列化和反序列化, 在qps较高时,json的序列化和反序列化 比较耗io,如有可能,使用

protocol buffer 做服务间的数据传输协议,取代json

字符串拼接时

尽量使用 strings.Joinstrings.Builder 减少内存重新分配

跨平台编译

To Windows from macOS

brew install mingw-w64.
CGO_ENABLED=1  CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64  go build 

To Windows from debian or ubuntu

sudo apt-get install gcc-mingw-w64
CGO_ENABLED=1  CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64  go build 

About

写go的一些经验

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published