Skip to content

Commit

Permalink
👔 up: arr,test - update field name for testutil.EchoReply, add alias …
Browse files Browse the repository at this point in the history
…func arrutil.StringsToAnys
  • Loading branch information
inhere committed Sep 1, 2023
1 parent 362bdcb commit b2889bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions arrutil/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func NewFormatter(arr any) *ArrFormatter {
return f
}

// FormatIndent array data to string.
func FormatIndent(arr any, indent string) string {
return NewFormatter(arr).WithIndent(indent).Format()
}

// WithFn for config self
func (f *ArrFormatter) WithFn(fn func(f *ArrFormatter)) *ArrFormatter {
fn(f)
Expand Down Expand Up @@ -116,8 +121,3 @@ func (f *ArrFormatter) doFormat() {
}
writer.WriteByte(']')
}

// FormatIndent array data to string.
func FormatIndent(arr any, indent string) string {
return NewFormatter(arr).WithIndent(indent).Format()
}
9 changes: 7 additions & 2 deletions arrutil/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package arrutil

import "strconv"

// StringsToSlice convert []string to []any
func StringsToSlice(ss []string) []any {
// StringsToAnys convert []string to []any
func StringsToAnys(ss []string) []any {
args := make([]any, len(ss))
for i, s := range ss {
args[i] = s
}
return args
}

// StringsToSlice convert []string to []any. alias of StringsToAnys()
func StringsToSlice(ss []string) []any {
return StringsToAnys(ss)
}

// StringsAsInts convert and ignore error
func StringsAsInts(ss []string) []int {
ints, _ := StringsTryInts(ss)
Expand Down
10 changes: 5 additions & 5 deletions testutil/httpmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func MockRequest(h http.Handler, method, path string, data *MD) *httptest.Respon
// EchoReply http response data reply model
type EchoReply struct {
Origin string `json:"origin"`
Url string `json:"url"`
URL string `json:"url"`
Method string `json:"method"`
// Query data
Query map[string]any `json:"query,omitempty"`
Headers map[string]any `json:"headers,omitempty"`
Form map[string]any `json:"form,omitempty"`
// Body data string
Body string `json:"body,omitempty"`
Json any `json:"json,omitempty"`
JSON any `json:"json,omitempty"`
Files map[string]any `json:"files,omitempty"`
}

Expand Down Expand Up @@ -213,11 +213,11 @@ func BuildEchoReply(r *http.Request) *EchoReply {
}

return &EchoReply{
Url: r.URL.String(),
URL: r.URL.String(),
Origin: r.RemoteAddr,
Method: method,
Body: bodyStr,
Json: jsonBody,
JSON: jsonBody,
Query: args,
Form: form,
Files: files,
Expand Down Expand Up @@ -251,7 +251,7 @@ func ParseRespToReply(w *http.Response) *EchoReply {
if w.Request != nil && w.Request.Method == "HEAD" {
req := w.Request
rpl := &EchoReply{
Url: req.URL.String(),
URL: req.URL.String(),
Method: req.Method,
Headers: stringsMapToAnyMap(req.Header),
}
Expand Down

0 comments on commit b2889bb

Please sign in to comment.