gout v0.2.6 版本更新,Go 实现的 http RESTful 客户端和 benchmark lib

栏目: 软件资讯 · 发布时间: 4年前

内容简介:项目地址 https://github.com/guonaihong/gout https://gitee.com/guonaihong/gout 本次更新 绑定数据支持校验 package main import ( "fmt" "time" "github.com/gin-gonic/gin" "github.com/guo...

项目地址

https://github.com/guonaihong/gout

https://gitee.com/guonaihong/gout

本次更新

绑定数据支持校验

package main

import (
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
	"github.com/guonaihong/gout"
)

type bodyJSON struct {
	Code int `valid:"required"`
}

func server() {
	r := gin.Default()
	r.GET("/have", func(c *gin.Context) {
		c.JSON(200, gin.H{"code": 200})
	})

	r.GET("/empty", func(c *gin.Context) {

	})

	r.Run()
}

func main() {
	go server()

	time.Sleep(time.Second / 100)

	b := bodyJSON{}

	err := gout.GET(":8080/have").BindJSON(&b).Do()
	fmt.Println(b, err)

	b = bodyJSON{}
	// 这里会报错, 因为bodyJSON里面的值为空, 到达数据校验的目的
	err = gout.GET(":8080/empty").BindJSON(&b).Do()
	fmt.Println(err)
}

feature

  • 支持设置 GET/PUT/DELETE/PATH/HEAD/OPTIONS
  • 支持设置请求 http header(可传 struct,map,array,slice 等类型)
  • 支持设置 URL query(可传 struct,map,array,slice,string 等类型)
  • 支持设置 json 编码到请求 body 里面(可传struct, map, string, []byte 等类型)
  • 支持设置 xml 编码到请求 body 里面(可传struct, string, []byte 等类型)
  • 支持设置 yaml 编码到请求 body 里面(可传struct, map, string, []byte 等类型)
  • 支持设置 protobuf 编码到请求 body里面(可传struct)
  • 支持设置 form-data(可传 struct, map, array, slice 等类型)
  • 支持设置 x-www-form-urlencoded(可传 struct,map,array,slice 等类型)
  • 支持设置 io.Reader,uint/uint8/uint16...int/int8...string...[]byte...float32,float64 至请求 body 里面
  • 支持解析响应body里面的json,xml,yaml至结构体里(BindJSON/BindXML/BindYAML)
  • 支持解析响应body的内容至io.Writer, uint/uint8...int/int8...string...[]byte...float32,float64
  • 支持解析响应header至结构体里
  • 支持接口性能benchmark,可控制压测一定次数还是时间,可控制压测频率
  • 支持retry-backoff,可以指定重试条件
  • 支持发送裸http数据包
  • 支持导出curl命令
  • 传入自定义*http.Client
  • 支持请求中间件(https://github.com/antlabs/gout-middleware)
  • 支持设置chunked数据格式发送
  • 支持body, header的数据校验
  • 等等更多

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Little MLer

The Little MLer

Matthias Felleisen、Daniel P. Friedman、Duane Bibby、Robin Milner / The MIT Press / 1998-2-19 / USD 34.00

The book, written in the style of The Little Schemer, introduces instructors, students, and practicioners to type-directed functional programming. It covers basic types, quickly moves into datatypes, ......一起来看看 《The Little MLer》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具