From f26477904e7ea02f826fe0c3a16fa163d652dd42 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Fri, 25 Feb 2022 15:31:39 +0800 Subject: [PATCH 1/5] refactor: set body byte for http post request --- netutil/net_internal.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/netutil/net_internal.go b/netutil/net_internal.go index de98f49..89d4687 100644 --- a/netutil/net_internal.go +++ b/netutil/net_internal.go @@ -157,16 +157,12 @@ func setQueryParam(req *http.Request, reqUrl string, queryParam interface{}) err func setBodyByte(req *http.Request, body interface{}) error { if body != nil { - var bodyByte []byte - if body != nil { - switch v := body.(type) { - case []byte: - bodyByte = v - default: - return errors.New("body type should be []byte") - } + switch b := body.(type) { + case []byte: + req.Body = ioutil.NopCloser(bytes.NewReader(b)) + default: + return errors.New("body type should be []byte") } - req.Body = ioutil.NopCloser(bytes.NewReader(bodyByte)) } return nil } From b3c34578bfaa9d17c23a0845361c335471a93c8f Mon Sep 17 00:00:00 2001 From: dudaodong Date: Fri, 25 Feb 2022 16:38:32 +0800 Subject: [PATCH 2/5] fix: set request body content-length --- netutil/net_internal.go | 1 + 1 file changed, 1 insertion(+) diff --git a/netutil/net_internal.go b/netutil/net_internal.go index 89d4687..f796091 100644 --- a/netutil/net_internal.go +++ b/netutil/net_internal.go @@ -160,6 +160,7 @@ func setBodyByte(req *http.Request, body interface{}) error { switch b := body.(type) { case []byte: req.Body = ioutil.NopCloser(bytes.NewReader(b)) + req.ContentLength = int64(len(b)) default: return errors.New("body type should be []byte") } From bab9b4a6b3c2fa3645538f453587631ade16f9ec Mon Sep 17 00:00:00 2001 From: dudaodong Date: Fri, 25 Feb 2022 16:39:03 +0800 Subject: [PATCH 3/5] release v1.2.5 --- README.md | 2 +- README_zh-CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ecf0868..73e37a2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
![Go version](https://img.shields.io/badge/go-%3E%3D1.16-9cf) -[![Release](https://img.shields.io/badge/release-1.2.4-green.svg)](https://github.com/duke-git/lancet/releases) +[![Release](https://img.shields.io/badge/release-1.2.5-green.svg)](https://github.com/duke-git/lancet/releases) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml) diff --git a/README_zh-CN.md b/README_zh-CN.md index 70d47c9..82b4ef4 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -4,7 +4,7 @@
![Go version](https://img.shields.io/badge/go-%3E%3D1.16-9cf) -[![Release](https://img.shields.io/badge/release-1.2.4-green.svg)](https://github.com/duke-git/lancet/releases) +[![Release](https://img.shields.io/badge/release-1.2.5-green.svg)](https://github.com/duke-git/lancet/releases) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml) From cd63b2b18f633d91bfd0f8eedf817a3b5fcf3650 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 28 Feb 2022 10:09:23 +0800 Subject: [PATCH 4/5] docs: add func UUIdV4 in readme file --- README.md | 2 +- README_zh-CN.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73e37a2..4bd7379 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,6 @@ import "github.com/duke-git/lancet/function" - [Compose](https://github.com/duke-git/lancet/blob/main/docs/function.md#Compose) - [Debounced](https://github.com/duke-git/lancet/blob/main/docs/function.md#Debounced) - [Delay](https://github.com/duke-git/lancet/blob/main/docs/function.md#Delay) -- [Delay](https://github.com/duke-git/lancet/blob/main/docs/function.md#Delay) - [Watcher](https://github.com/duke-git/lancet/blob/main/docs/function.md#Watcher) ### Netutil package contains functions to get net information and send http request. @@ -225,6 +224,7 @@ import "github.com/duke-git/lancet/random" - [RandBytes](https://github.com/duke-git/lancet/blob/main/docs/random.md#RandBytes) - [RandInt](https://github.com/duke-git/lancet/blob/main/docs/random.md#RandInt) - [RandString](https://github.com/duke-git/lancet/blob/main/docs/random.md#RandString) +- [UUIdV4](https://github.com/duke-git/lancet/blob/main/docs/random.md#UUIdV4) ### Retry package is for executing a function repeatedly until it was successful or canceled by the context. diff --git a/README_zh-CN.md b/README_zh-CN.md index 82b4ef4..6cee56c 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -193,7 +193,6 @@ import "github.com/duke-git/lancet/function" - [Compose](https://github.com/duke-git/lancet/blob/main/docs/function_zh-CN.md#Compose) - [Debounced](https://github.com/duke-git/lancet/blob/main/docs/function_zh-CN.md#Debounced) - [Delay](https://github.com/duke-git/lancet/blob/main/docs/function_zh-CN.md#Delay) -- [Delay](https://github.com/duke-git/lancet/blob/main/docs/function_zh-CN.md#Delay) - [Watcher](https://github.com/duke-git/lancet/blob/main/docs/function_zh-CN.md#Watcher) @@ -227,7 +226,7 @@ import "github.com/duke-git/lancet/random" - [RandBytes](https://github.com/duke-git/lancet/blob/main/docs/random_zh-CN.md#RandBytes) - [RandInt](https://github.com/duke-git/lancet/blob/main/docs/random_zh-CN.md#RandInt) - [RandString](https://github.com/duke-git/lancet/blob/main/docs/random_zh-CN.md#RandString) - +- [UUIdV4](https://github.com/duke-git/lancet/blob/main/docs/random.md#UUIdV4) ### retry重试执行函数直到函数运行成功或被context cancel。 ```go From f1fd4c876b1b0955bbc685b35fd0108ec4ccaf16 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 28 Feb 2022 10:11:07 +0800 Subject: [PATCH 5/5] fmt: gofmt function.go --- function/function.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/function/function.go b/function/function.go index bdabb62..6e2cddb 100644 --- a/function/function.go +++ b/function/function.go @@ -13,7 +13,7 @@ import ( func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value { // Catch programming error while constructing the closure mustBeFunction(fn) - + return func(args ...interface{}) []reflect.Value { n-- if n < 1 {