Skip to content

Commit

Permalink
Use slices.Contains
Browse files Browse the repository at this point in the history
  • Loading branch information
alexedwards committed Oct 22, 2023
1 parent cf11be9 commit 1828f58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 3 additions & 11 deletions flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
"context"
"net/http"
"regexp"
"slices"
"strings"
)

Expand Down Expand Up @@ -111,7 +112,7 @@ func New() *Mux {
// Handle registers a new handler for the given request path pattern and HTTP
// methods.
func (m *Mux) Handle(pattern string, handler http.Handler, methods ...string) {
if contains(methods, http.MethodGet) && !contains(methods, http.MethodHead) {
if slices.Contains(methods, http.MethodGet) && !slices.Contains(methods, http.MethodHead) {
methods = append(methods, http.MethodHead)
}

Expand Down Expand Up @@ -174,7 +175,7 @@ func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
route.handler.ServeHTTP(w, r.WithContext(ctx))
return
}
if !contains(allowedMethods, route.method) {
if !slices.Contains(allowedMethods, route.method) {
allowedMethods = append(allowedMethods, route.method)
}
}
Expand All @@ -201,15 +202,6 @@ func (m *Mux) wrap(handler http.Handler) http.Handler {
return handler
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

type route struct {
method string
segments []string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/alexedwards/flow

go 1.17
go 1.21

0 comments on commit 1828f58

Please sign in to comment.