golang
已收录文章:12155篇
-
使用Golang的compress/zlib包可实现zlib格式的数据压缩与解压。1.压缩数据时,通过zlib.NewWriter创建写入器,将数据写入缓冲区并调用Close()完成压缩;2.解压数据时,使用zlib.NewReader读取压缩流并通过io.Copy提取原始数据,并记得关闭读取器;3.实际应用中可在HTTP请求头设置Content-Encoding为zlib,客户端压缩发送、服务端识别并解压处理;4.压缩级别可调整,BestCompression(9)提供最高压缩率,BestSpeed(1163 收藏
-
网上很多资源都说是xorm reverse mysql "root:123456@tcp(127.0.0.1:3306)/users?charset=utf8" ./ 执行后报错:2022/03/16 15:00:53 [Error] reverse.go:196 Unknown colType INT UNSIGNED 实际上原有的xorm 已经不能用了,现在162 收藏
-
使用channel实现协程池 通过 Channel 实现 Goroutine Pool,缺点是会造成协程的频繁开辟和注销,但好在简单灵活通用。 package main import ( "fmt" "io/ioutil" "net/http" "sync" ) // Pool goroutine Pool type Pool struct162 收藏
-
在go语言中,byte其实是uint8的别名,byte 和 uint8 之间可以直接进行互转。 目前来只能将0~255范围的int转成byte。 func Int64ToBytes(num int64) []uint8 { var buffer bytes.Buffer err := binary.Write(&buffer, binary.Big162 收藏
-
看代码吧~ //自定义结构体,用来自定义排序 type RecentlyUpdateListMapSorter []map[string]interface{} //根据MapSorter.Keys进行倒序排序 func (ms *RecentlyUpdateListMapSorter) SortReverse() { sort.Sort(sort.Reverse(ms)) } //自定义162 收藏
-
超时 建立连接 主要就2函数Dail和DialContext。 // Dial creates a client connection to the given target. func Dial(target string, opts ...DialOption) (*ClientConn, error) { return DialContext(context.Background(), target, opts...) } fun162 收藏