-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: run rekres (update to Go 1.22)
Update `handlers` function to match new `http.ServeMux` internals. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
- Loading branch information
Showing
9 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
//go:build !go1.22 | ||
|
||
package debug | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"slices" | ||
) | ||
|
||
// handlers returns all patterns registered on the default HTTP server mux. | ||
// Useful to check for unexpected handlers. | ||
func handlers() []string { | ||
keys := reflect.ValueOf(http.DefaultServeMux).Elem().FieldByName("m").MapKeys() | ||
|
||
res := make([]string, len(keys)) | ||
for i, v := range keys { | ||
res[i] = v.String() | ||
} | ||
|
||
slices.Sort(res) | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
//go:build go1.22 && !go1.23 | ||
|
||
package debug | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"slices" | ||
) | ||
|
||
// handlers returns all patterns registered on the default HTTP server mux. | ||
// Useful to check for unexpected handlers. | ||
func handlers() []string { | ||
// This will only work for Go 1.22, since `http.ServeMux.patterns` contains "remove if possible" comment string | ||
// from Go developers. | ||
patterns := reflect.ValueOf(http.DefaultServeMux).Elem().FieldByName("patterns") | ||
pLen := patterns.Len() | ||
|
||
res := make([]string, pLen) | ||
for i := 0; i < pLen; i++ { | ||
res[i] = patterns.Index(i).Elem().FieldByName("str").String() | ||
} | ||
|
||
slices.Sort(res) | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters