Skip to content

Commit

Permalink
✨ up(net,sys): update some sys and net util func logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 1, 2023
1 parent 346870e commit fad9894
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions netutil/httpreq/client.go
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions netutil/httpreq/util.go
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions reflects/check.go
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions sysutil/sysutil.go
Expand Up @@ -3,7 +3,6 @@ package sysutil

import (
"os"
"path"
"path/filepath"
)

Expand All @@ -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
Expand Down

0 comments on commit fad9894

Please sign in to comment.