diff --git a/arrutil/format.go b/arrutil/format.go index b549bcc55..5e2f91091 100644 --- a/arrutil/format.go +++ b/arrutil/format.go @@ -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) @@ -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() -} diff --git a/arrutil/strings.go b/arrutil/strings.go index 920f54351..ef3fa6cfd 100644 --- a/arrutil/strings.go +++ b/arrutil/strings.go @@ -2,8 +2,8 @@ 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 @@ -11,6 +11,11 @@ func StringsToSlice(ss []string) []any { 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) diff --git a/testutil/httpmock.go b/testutil/httpmock.go index 70a716193..2c53f88f9 100644 --- a/testutil/httpmock.go +++ b/testutil/httpmock.go @@ -113,7 +113,7 @@ 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"` @@ -121,7 +121,7 @@ type EchoReply struct { 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"` } @@ -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, @@ -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), }