V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
guonaihong
V2EX  ›  Go 编程语言

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

  •  
  •   guonaihong ·
    guonaihong · 2020-05-25 09:31:57 +08:00 · 2683 次点击
    这是一个创建于 1403 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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)
        }
    }
    
    11 条回复    2020-06-11 14:06:39 +08:00
    wysnylc
        1
    wysnylc  
       2020-05-25 10:18:45 +08:00
    python 党出来,就照这样写个轮子
    lasuar
        2
    lasuar  
       2020-05-25 10:25:04 +08:00
    也用 go,给个 star !
    guonaihong
        3
    guonaihong  
    OP
       2020-05-25 13:43:09 +08:00
    @lasuar 感谢支持。。。
    guonaihong
        4
    guonaihong  
    OP
       2020-05-25 18:41:19 +08:00
    @wysnylc 看过你的留言,哈哈,你不是用 java 的吗。。。
    wysnylc
        5
    wysnylc  
       2020-05-25 18:45:14 +08:00
    @guonaihong #4 Java 只是副业,主业是键盘侠
    prenwang
        6
    prenwang  
       2020-06-04 22:03:14 +08:00
    @guonaihong 感谢造出这么好用的裤子.
    guonaihong
        7
    guonaihong  
    OP
       2020-06-05 13:34:20 +08:00
    @prenwang 也感谢你的使用,哈哈。。。
    u823tg
        8
    u823tg  
       2020-06-08 14:48:37 +08:00
    很 nice,就是最近不怎么用 go 了,我果然是个见异思迁的。哈哈哈
    johng
        9
    johng  
       2020-06-11 00:58:44 +08:00
    @guonaihong 架构图画得不错,是用的 processon 吗?
    guonaihong
        10
    guonaihong  
    OP
       2020-06-11 14:04:54 +08:00
    @johng 是的。
    guonaihong
        11
    guonaihong  
    OP
       2020-06-11 14:06:39 +08:00
    @u823tg 哈哈。。。下次可以玩 rust 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   969 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:21 · PVG 04:21 · LAX 13:21 · JFK 16:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.