golang 实现的 http client 库,新版本带来新功能(gout-v0.0.12)
資深大佬 : guonaihong 2
gout
golang 实现的 http 请求库。本次版本带来一些细节上的优化。http 请求库作用是让你发送 json/formdata 之类数据更 easy,bind 数据更爽。gout 除了是 restful api 库还是压测 lib,可以完成 ab, wrk 完成的工作。
版本及地址
本次版本是 v0.0.12
https://github.com/guonaihong/gout
下个版本计划
提升压测子模块的吞吐效率。
压测功能回顾
自定义压测函数,构造每次不一样的 http request 数据。 相比 wrk 需要写 lua,在 go lib 里面解决自定义压测会更 easy
package main import ( "fmt" "github.com/google/uuid" "github.com/guonaihong/gout" "github.com/guonaihong/gout/filter" "sync/atomic" ) func main() { i := int32(0) err := filter.NewBench(). Concurrent(30). //开 30 个 go 程 Number(30000). //压测 30000 次 Loop(func(c *gout.Context) error { // 下面的代码,每次生成不一样的 http body 用于压测 uid := uuid.New() //生成 uuid id := atomic.AddInt32(&i, 1) //生成 id, 可以理解为++i,线程安全版本 c.POST(":1234").SetJSON(gout.H{"sid": uid.String(), "appkey": fmt.Sprintf("ak:%d", id), "text": fmt.Sprintf("test text :%d", id)}) //这里不要运行 Do()函数 return nil }).Do() if err != nil { fmt.Printf("err = %vn", err) } }
大佬有話說 (5)