fix nil nmsg in case of empty request body

This commit is contained in:
Nurzhan Ilyassov
2024-03-26 11:09:38 +05:00
committed by Vasiliy Tolstov
parent 9149aeb3de
commit 4c2178305d
2 changed files with 33 additions and 1 deletions

10
util.go
View File

@@ -217,13 +217,21 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
_, _ = b.WriteString(values.Encode())
}
if rutil.IsZero(nmsg) {
if rutil.IsZero(nmsg) && !isEmptyStruct(nmsg) {
return b.String(), nil, nil
}
return b.String(), nmsg, nil
}
func isEmptyStruct(v interface{}) bool {
val := reflect.ValueOf(v)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
return val.Kind() == reflect.Struct && val.NumField() == 0
}
func newTemplate(path string) ([]string, error) {
if len(path) == 0 || path[0] != '/' {
return nil, fmt.Errorf("path must starts with /")