gout请求和响应中间件项目
import (
"github.com/antlabs/gout-middleware/request"
"github.com/guonaihong/gout"
)
func main() {
gout.POST(":6666/compress").
RequestUse(request.GzipCompress()).
SetBody("hello world").
Do()
}
import (
"github.com/antlabs/gout-middleware/request"
"github.com/guonaihong/gout"
)
func main() {
gout.POST(":6666/compress").
RequestUse(request.GzipCompress(request.EnableGzipGreaterEqual(4))). //大于等于4个字节才压缩
SetBody("hello world").
Do()
}
import (
"github.com/antlabs/gout-middleware/request"
"github.com/guonaihong/gout"
"bytes"
)
func main() {
var buf bytes.Buffer //假装buf里面有gzip数据
gout.POST(":6666/compress").RequestUse(request.GzipDecompress()).SetBody(buf).Do()
}
package main
import (
"bytes"
"github.com/antlabs/gout-middleware/request"
"github.com/guonaihong/gout"
)
func main() {
gout.POST(":8080").RequestUse(request.ProgressBar(func(currBytes, totalBytes int) {
fmt.Printf("%d:%d-->%f%%\n", currBytes, totalBytes, float64(currBytes)/float64(totalBytes))
})).SetBody(strings.Repeat("1", 100000) /*构造大点的测试数据,这里换成真实业务数据*/).Do()
}
package main
import (
"github.com/antlabs/gout-middleware/request"
"github.com/guonaihong/gout"
"net/http"
)
func main() {
c := &http.Client{}
gout.New(c).GET(":8080/301").RequestUse(request.Close3xx(c, true)).Do()
}