diff --git a/g/net/ghttp/ghttp_request.go b/g/net/ghttp/ghttp_request.go index 3f504eba0..742582a2e 100644 --- a/g/net/ghttp/ghttp_request.go +++ b/g/net/ghttp/ghttp_request.go @@ -79,7 +79,7 @@ func (r *Request) GetVar(key string, def ... interface{}) gvar.VarRead { return r.GetRequestVar(key, def...) } -// 获取原始请求输入字符串 +// 获取原始请求输入二进制。 func (r *Request) GetRaw() []byte { if r.rawContent == nil { r.rawContent, _ = ioutil.ReadAll(r.Body) @@ -87,6 +87,14 @@ func (r *Request) GetRaw() []byte { return r.rawContent } +// 获取原始请求输入字符串。 +func (r *Request) GetRawString() string { + if r.rawContent == nil { + r.rawContent, _ = ioutil.ReadAll(r.Body) + } + return string(r.rawContent) +} + // 获取原始json请求输入字符串,并解析为json对象 func (r *Request) GetJson() *gjson.Json { data := r.GetRaw() diff --git a/g/net/ghttp/ghttp_request_query.go b/g/net/ghttp/ghttp_request_query.go index b5a26e832..811c03daf 100644 --- a/g/net/ghttp/ghttp_request_query.go +++ b/g/net/ghttp/ghttp_request_query.go @@ -16,9 +16,10 @@ func (r *Request) initGet() { if !r.parsedGet { r.queryVars = r.URL.Query() if strings.EqualFold(r.Method, "GET") { - if raw := r.GetRaw(); len(raw) > 0 { - for _, item := range strings.Split(string(raw), "&") { - array := strings.Split(item, "=") + if raw := r.GetRawString(); len(raw) > 0 { + var array []string + for _, item := range strings.Split(raw, "&") { + array = strings.Split(item, "=") r.queryVars[array[0]] = append(r.queryVars[array[0]], array[1]) } } diff --git a/g/net/ghttp/ghttp_unit_param_test.go b/g/net/ghttp/ghttp_unit_param_test.go index e2e2dad74..2816e647e 100644 --- a/g/net/ghttp/ghttp_unit_param_test.go +++ b/g/net/ghttp/ghttp_unit_param_test.go @@ -16,7 +16,7 @@ import ( "time" ) -func Test_Params(t *testing.T) { +func Test_Params_Basic(t *testing.T) { type User struct { Id int Name string diff --git a/g/text/gstr/gstr_pos.go b/g/text/gstr/gstr_pos.go index a4f2d037b..107cb5c58 100644 --- a/g/text/gstr/gstr_pos.go +++ b/g/text/gstr/gstr_pos.go @@ -9,6 +9,7 @@ package gstr import "strings" // Find the position of the first occurrence of a substring in a string. +// It returns -1, if none found. // // 返回 needle 在 haystack 中首次出现的数字位置,找不到返回-1。 func Pos(haystack, needle string, startOffset...int) int { @@ -32,6 +33,7 @@ func Pos(haystack, needle string, startOffset...int) int { } // Find the position of the first occurrence of a case-insensitive substring in a string. +// It returns -1, if none found. // // 返回在字符串 haystack 中 needle 首次出现的数字位置(不区分大小写),找不到返回-1。 func PosI(haystack, needle string, startOffset...int) int { @@ -56,6 +58,7 @@ func PosI(haystack, needle string, startOffset...int) int { } // Find the position of the last occurrence of a substring in a string. +// It returns -1, if none found. // // 查找指定字符串在目标字符串中最后一次出现的位置,找不到返回-1。 func PosR(haystack, needle string, startOffset...int) int { @@ -81,6 +84,7 @@ func PosR(haystack, needle string, startOffset...int) int { } // Find the position of the last occurrence of a case-insensitive substring in a string. +// It returns -1, if none found. // // 以不区分大小写的方式查找指定字符串在目标字符串中最后一次出现的位置,找不到返回-1。 func PosRI(haystack, needle string, startOffset...int) int {