05 2022 档案
摘要:在go语言中,上下文context.Context用来设置截止日期、同步信号、传递请求相关值得结构体。上下文与Goroutine得关系比较密切,是go语言中独特得设计,在其他编程语言中很少见到类似的概念。 context.Context是一个接口,定义了如下四个方法: // A Context ca
阅读全文
摘要:centos6 开机脚本 centos6可以使用service和chkconfig来配置开机脚本,例如 配置开机脚本放在/etc/init.t目录下,如源码安装postgresql时开机运行contrib/start-scripts/linux放在此目录下并重命名为postgresql脚本放在/et
阅读全文
摘要:bytes.buffer定义如下: // A Buffer is a variable-sized buffer of bytes with Read and Write methods. // The zero value for Buffer is an empty buffer ready t
阅读全文
摘要:将map或struct转为jsonstr: package main import ( "encoding/json" "fmt" ) func main() { mymap := make(map[string]string) mymap["name"] = "zhang" mymap["addr
阅读全文
摘要:例如tcp连接、数据库连接这类耗时的操作,可以放在池中,避免每次使用时都重新创建。 池化的对象可能会被垃圾回收,对于数据库的长链接是不合适的。 因此有专门用于TCP连接池、数据库连接池,还会有一种常见的Woker Pool。 注意点: (1) sync.Pool本身线程安全,多个goroutine可
阅读全文