From 2e279f492cc6c5015989a757750820e43548318b Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Mon, 6 Apr 2026 16:04:47 +0300 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20apply=20De=20Morgan=E2=80=99s?= =?UTF-8?q?=20law=20to=20boolean=20expressions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bind.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bind.go b/bind.go index 050e8973b..31bf308e0 100644 --- a/bind.go +++ b/bind.go @@ -155,7 +155,7 @@ func bindData(destination any, data map[string][]string, tag string, dataFiles m isElemInterface := k == reflect.Interface isElemString := k == reflect.String isElemSliceOfStrings := k == reflect.Slice && typ.Elem().Elem().Kind() == reflect.String - if !(isElemSliceOfStrings || isElemString || isElemInterface) { + if !isElemSliceOfStrings && !isElemString && !isElemInterface { return nil } if val.IsNil() { From 852d2b39f89f6217df42816008f31335420e0a0c Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Mon, 6 Apr 2026 16:15:56 +0300 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20apply=20De=20Morgan=E2=80=99s?= =?UTF-8?q?=20law=20to=20boolean=20expressions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/basic_auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/basic_auth.go b/middleware/basic_auth.go index e0a284c67..890a47bd8 100644 --- a/middleware/basic_auth.go +++ b/middleware/basic_auth.go @@ -121,7 +121,7 @@ func (config BasicAuthConfig) ToMiddleware() (echo.MiddlewareFunc, error) { if i >= limit { break } - if !(len(auth) > l+1 && strings.EqualFold(auth[:l], basic)) { + if len(auth) <= l+1 || !strings.EqualFold(auth[:l], basic) { continue } i++ From db0359e3c67faaba64cc8daa1a820a87611b32ec Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Mon, 6 Apr 2026 16:20:09 +0300 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20apply=20De=20Morgan=E2=80=99s?= =?UTF-8?q?=20law=20to=20boolean=20expressions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- middleware/static.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/static.go b/middleware/static.go index 452603325..a9e67b626 100644 --- a/middleware/static.go +++ b/middleware/static.go @@ -250,7 +250,7 @@ func (config StaticConfig) ToMiddleware() (echo.MiddlewareFunc, error) { } var he echo.HTTPStatusCoder - if !(errors.As(err, &he) && config.HTML5 && he.StatusCode() == http.StatusNotFound) { + if !errors.As(err, &he) || !config.HTML5 || he.StatusCode() != http.StatusNotFound { return err } // is case HTML5 mode is enabled + echo 404 we serve index to the client From f5df1132a00af9b2886dac4db3aa7048219cf7eb Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Mon, 6 Apr 2026 16:23:55 +0300 Subject: [PATCH 4/6] perf: replace fmt.Sprintf with fmt.Fprintf --- route.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/route.go b/route.go index 3a5291b00..b986296b0 100644 --- a/route.go +++ b/route.go @@ -85,8 +85,8 @@ func (r RouteInfo) Reverse(pathValues ...any) string { // in case of `*` wildcard or `:` (unescaped colon) param we replace everything till next slash or end of path for ; i < l && r.Path[i] != '/'; i++ { } - uri.WriteString(fmt.Sprintf("%v", pathValues[n])) - n++ + fmt.Fprintf(uri, "%v", pathValues[n]) + n++ } if i < l { uri.WriteByte(r.Path[i]) From 11ab0e48187b0fd4ad902e8fad0c27f4bdfe09a7 Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Mon, 6 Apr 2026 16:25:33 +0300 Subject: [PATCH 5/6] refactor: remove redundant embedded field access --- router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router.go b/router.go index 0db3bc04c..48341cb1b 100644 --- a/router.go +++ b/router.go @@ -995,7 +995,7 @@ func (r *DefaultRouter) Route(c *Context) HandlerFunc { var rInfo *RouteInfo if matchedRouteMethod != nil { rHandler = matchedRouteMethod.handler - rPath = matchedRouteMethod.RouteInfo.Path + rPath = matchedRouteMethod.Path rInfo = matchedRouteMethod.RouteInfo } else { // use previous match as basis. although we have no matching handler we have path match. From b1d350e89e7a2a3eec2cc54b38dfa3820415aa8f Mon Sep 17 00:00:00 2001 From: itsllyaz Date: Tue, 7 Apr 2026 06:17:46 +0300 Subject: [PATCH 6/6] fix: Correct indentation with go fmt --- bind.go | 2 +- binder_generic.go | 70 ++++++++++++++++++++++++++--------------------- response.go | 2 +- route.go | 2 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/bind.go b/bind.go index 31bf308e0..83bd11a9b 100644 --- a/bind.go +++ b/bind.go @@ -155,7 +155,7 @@ func bindData(destination any, data map[string][]string, tag string, dataFiles m isElemInterface := k == reflect.Interface isElemString := k == reflect.String isElemSliceOfStrings := k == reflect.Slice && typ.Elem().Elem().Kind() == reflect.String - if !isElemSliceOfStrings && !isElemString && !isElemInterface { + if !isElemSliceOfStrings && !isElemString && !isElemInterface { return nil } if val.IsNil() { diff --git a/binder_generic.go b/binder_generic.go index 0c0eb9089..62e1da512 100644 --- a/binder_generic.go +++ b/binder_generic.go @@ -49,10 +49,11 @@ const ( // It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found. // // Empty String Handling: -// If the parameter exists but has an empty value, the zero value of type T is returned -// with no error. For example, a path parameter with value "" returns (0, nil) for int types. -// This differs from standard library behavior where parsing empty strings returns errors. -// To treat empty values as errors, validate the result separately or check the raw value. +// +// If the parameter exists but has an empty value, the zero value of type T is returned +// with no error. For example, a path parameter with value "" returns (0, nil) for int types. +// This differs from standard library behavior where parsing empty strings returns errors. +// To treat empty values as errors, validate the result separately or check the raw value. // // See ParseValue for supported types and options func PathParam[T any](c *Context, paramName string, opts ...any) (T, error) { @@ -74,10 +75,11 @@ func PathParam[T any](c *Context, paramName string, opts ...any) (T, error) { // Returns an error only if parsing fails (e.g., "abc" for int type). // // Example: -// id, err := echo.PathParamOr[int](c, "id", 0) -// // If "id" is missing: returns (0, nil) -// // If "id" is "123": returns (123, nil) -// // If "id" is "abc": returns (0, BindingError) +// +// id, err := echo.PathParamOr[int](c, "id", 0) +// // If "id" is missing: returns (0, nil) +// // If "id" is "123": returns (123, nil) +// // If "id" is "abc": returns (0, BindingError) // // See ParseValue for supported types and options func PathParamOr[T any](c *Context, paramName string, defaultValue T, opts ...any) (T, error) { @@ -97,10 +99,11 @@ func PathParamOr[T any](c *Context, paramName string, defaultValue T, opts ...an // It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found. // // Empty String Handling: -// If the parameter exists but has an empty value (?key=), the zero value of type T is returned -// with no error. For example, "?count=" returns (0, nil) for int types. -// This differs from standard library behavior where parsing empty strings returns errors. -// To treat empty values as errors, validate the result separately or check the raw value. +// +// If the parameter exists but has an empty value (?key=), the zero value of type T is returned +// with no error. For example, "?count=" returns (0, nil) for int types. +// This differs from standard library behavior where parsing empty strings returns errors. +// To treat empty values as errors, validate the result separately or check the raw value. // // Behavior Summary: // - Missing key (?other=value): returns (zero, ErrNonExistentKey) @@ -131,10 +134,11 @@ func QueryParam[T any](c *Context, key string, opts ...any) (T, error) { // Returns an error only if parsing fails (e.g., "abc" for int type). // // Example: -// page, err := echo.QueryParamOr[int](c, "page", 1) -// // If "page" is missing: returns (1, nil) -// // If "page" is "5": returns (5, nil) -// // If "page" is "abc": returns (1, BindingError) +// +// page, err := echo.QueryParamOr[int](c, "page", 1) +// // If "page" is missing: returns (1, nil) +// // If "page" is "5": returns (5, nil) +// // If "page" is "abc": returns (1, BindingError) // // See ParseValue for supported types and options func QueryParamOr[T any](c *Context, key string, defaultValue T, opts ...any) (T, error) { @@ -175,10 +179,11 @@ func QueryParams[T any](c *Context, key string, opts ...any) ([]T, error) { // Returns an error only if parsing any value fails. // // Example: -// ids, err := echo.QueryParamsOr[int](c, "ids", []int{}) -// // If "ids" is missing: returns ([], nil) -// // If "ids" is "1&ids=2": returns ([1, 2], nil) -// // If "ids" contains "abc": returns ([], BindingError) +// +// ids, err := echo.QueryParamsOr[int](c, "ids", []int{}) +// // If "ids" is missing: returns ([], nil) +// // If "ids" is "1&ids=2": returns ([1, 2], nil) +// // If "ids" contains "abc": returns ([], BindingError) // // See ParseValues for supported types and options func QueryParamsOr[T any](c *Context, key string, defaultValue []T, opts ...any) ([]T, error) { @@ -198,10 +203,11 @@ func QueryParamsOr[T any](c *Context, key string, defaultValue []T, opts ...any) // It returns the typed value and an error if binding fails. Returns ErrNonExistentKey if parameter not found. // // Empty String Handling: -// If the form field exists but has an empty value, the zero value of type T is returned -// with no error. For example, an empty form field returns (0, nil) for int types. -// This differs from standard library behavior where parsing empty strings returns errors. -// To treat empty values as errors, validate the result separately or check the raw value. +// +// If the form field exists but has an empty value, the zero value of type T is returned +// with no error. For example, an empty form field returns (0, nil) for int types. +// This differs from standard library behavior where parsing empty strings returns errors. +// To treat empty values as errors, validate the result separately or check the raw value. // // See ParseValue for supported types and options func FormValue[T any](c *Context, key string, opts ...any) (T, error) { @@ -232,10 +238,11 @@ func FormValue[T any](c *Context, key string, opts ...any) (T, error) { // Returns an error only if parsing fails or form parsing errors occur. // // Example: -// limit, err := echo.FormValueOr[int](c, "limit", 100) -// // If "limit" is missing: returns (100, nil) -// // If "limit" is "50": returns (50, nil) -// // If "limit" is "abc": returns (100, BindingError) +// +// limit, err := echo.FormValueOr[int](c, "limit", 100) +// // If "limit" is missing: returns (100, nil) +// // If "limit" is "50": returns (50, nil) +// // If "limit" is "abc": returns (100, BindingError) // // See ParseValue for supported types and options func FormValueOr[T any](c *Context, key string, defaultValue T, opts ...any) (T, error) { @@ -284,9 +291,10 @@ func FormValues[T any](c *Context, key string, opts ...any) ([]T, error) { // Returns an error only if parsing any value fails or form parsing errors occur. // // Example: -// tags, err := echo.FormValuesOr[string](c, "tags", []string{}) -// // If "tags" is missing: returns ([], nil) -// // If form parsing fails: returns (nil, error) +// +// tags, err := echo.FormValuesOr[string](c, "tags", []string{}) +// // If "tags" is missing: returns ([], nil) +// // If form parsing fails: returns (nil, error) // // See ParseValues for supported types and options func FormValuesOr[T any](c *Context, key string, defaultValue []T, opts ...any) ([]T, error) { diff --git a/response.go b/response.go index 09a8a828d..4da729c47 100644 --- a/response.go +++ b/response.go @@ -136,7 +136,7 @@ func UnwrapResponse(rw http.ResponseWriter) (*Response, error) { type delayedStatusWriter struct { http.ResponseWriter committed bool - status int + status int } func (w *delayedStatusWriter) WriteHeader(statusCode int) { diff --git a/route.go b/route.go index b986296b0..970520435 100644 --- a/route.go +++ b/route.go @@ -86,7 +86,7 @@ func (r RouteInfo) Reverse(pathValues ...any) string { for ; i < l && r.Path[i] != '/'; i++ { } fmt.Fprintf(uri, "%v", pathValues[n]) - n++ + n++ } if i < l { uri.WriteByte(r.Path[i])