golang 实现的 http client 库,新版本带来新功能(gout-v0.0.12)

2020-05-25 09:31:57 +08:00
 guonaihong

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 = %v\n", err)
    }
}
2697 次点击
所在节点    Go 编程语言
11 条回复
wysnylc
2020-05-25 10:18:45 +08:00
python 党出来,就照这样写个轮子
lasuar
2020-05-25 10:25:04 +08:00
也用 go,给个 star !
guonaihong
2020-05-25 13:43:09 +08:00
@lasuar 感谢支持。。。
guonaihong
2020-05-25 18:41:19 +08:00
@wysnylc 看过你的留言,哈哈,你不是用 java 的吗。。。
wysnylc
2020-05-25 18:45:14 +08:00
@guonaihong #4 Java 只是副业,主业是键盘侠
prenwang
2020-06-04 22:03:14 +08:00
@guonaihong 感谢造出这么好用的裤子.
guonaihong
2020-06-05 13:34:20 +08:00
@prenwang 也感谢你的使用,哈哈。。。
u823tg
2020-06-08 14:48:37 +08:00
很 nice,就是最近不怎么用 go 了,我果然是个见异思迁的。哈哈哈
johng
2020-06-11 00:58:44 +08:00
@guonaihong 架构图画得不错,是用的 processon 吗?
guonaihong
2020-06-11 14:04:54 +08:00
@johng 是的。
guonaihong
2020-06-11 14:06:39 +08:00
@u823tg 哈哈。。。下次可以玩 rust 。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/675084

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX