diff --git a/netutil/httpreq/client.go b/netutil/httpreq/client.go index 7b21ef050..9f2e2e347 100644 --- a/netutil/httpreq/client.go +++ b/netutil/httpreq/client.go @@ -20,6 +20,8 @@ type ReqOption struct { HeaderMap map[string]string // Timeout unit: ms Timeout int + // TCancelFunc will auto set it on Timeout > 0 + TCancelFunc context.CancelFunc // ContentType header ContentType string // EncodeJSON req body diff --git a/netutil/httpreq/util.go b/netutil/httpreq/util.go index 89f8fdc98..62762703a 100644 --- a/netutil/httpreq/util.go +++ b/netutil/httpreq/util.go @@ -254,11 +254,14 @@ func ResponseToString(w *http.Response) string { buf.WriteString(w.Status) buf.WriteByte('\n') - for key, values := range w.Header { - buf.WriteString(key) - buf.WriteString(": ") - buf.WriteString(strings.Join(values, ";")) + if len(w.Header) > 0 { buf.WriteByte('\n') + for key, values := range w.Header { + buf.WriteString(key) + buf.WriteString(": ") + buf.WriteString(strings.Join(values, ";")) + buf.WriteByte('\n') + } } if w.Body != nil { diff --git a/reflects/check.go b/reflects/check.go index 804eba08b..0045cf75c 100644 --- a/reflects/check.go +++ b/reflects/check.go @@ -19,6 +19,21 @@ func IsArrayOrSlice(k reflect.Kind) bool { return k == reflect.Slice || k == reflect.Array } +// IsAnyInt check is intX or uintX type +func IsAnyInt(k reflect.Kind) bool { + return k >= reflect.Int && k <= reflect.Uintptr +} + +// IsIntx check is intX or uintX type +func IsIntx(k reflect.Kind) bool { + return k >= reflect.Int && k <= reflect.Int64 +} + +// IsUintX check is intX or uintX type +func IsUintX(k reflect.Kind) bool { + return k >= reflect.Uint && k <= reflect.Uintptr +} + // IsNil reflect value func IsNil(v reflect.Value) bool { switch v.Kind() { diff --git a/sysutil/sysutil.go b/sysutil/sysutil.go index 9e3b176e6..f2574d203 100644 --- a/sysutil/sysutil.go +++ b/sysutil/sysutil.go @@ -3,7 +3,6 @@ package sysutil import ( "os" - "path" "path/filepath" ) @@ -15,12 +14,12 @@ func Workdir() string { // BinDir get func BinDir() string { - return path.Dir(os.Args[0]) + return filepath.Dir(os.Args[0]) } // BinName get func BinName() string { - return path.Base(os.Args[0]) + return filepath.Base(os.Args[0]) } // BinFile get