Skip to content

Commit d21bc16

Browse files
committed
refactor(http): use slices.Contains for method validation
- Refactor method validation to use `slices.Contains` instead of a loop.
1 parent 373b605 commit d21bc16

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

internal/http/manager.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net/http"
88
"net/url"
9+
"slices"
910
"strings"
1011
"time"
1112

@@ -24,10 +25,8 @@ func NewHTTPManager() *HTTPManager {
2425
func validateMethod(method string) error {
2526
method = strings.ToUpper(strings.TrimSpace(method))
2627
validMethods := []string{"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"}
27-
for _, valid := range validMethods {
28-
if method == valid {
29-
return nil
30-
}
28+
if slices.Contains(validMethods, method) {
29+
return nil
3130
}
3231
return fmt.Errorf("invalid HTTP method: %s", method)
3332
}

0 commit comments

Comments
 (0)