Code refactoring for #1939
This commit is contained in:
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Debug go2rtc",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"env": {
|
||||
"CGO_ENABLED": "0"
|
||||
},
|
||||
"program": "main.go",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -178,11 +178,5 @@ func apiPreload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func apiSchemes(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" {
|
||||
http.Error(w, "", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
schemes := GetSupportedSchemes()
|
||||
api.ResponseJSON(w, schemes)
|
||||
api.ResponseJSON(w, SupportedSchemes())
|
||||
}
|
||||
|
||||
@@ -35,20 +35,6 @@ func TestApiSchemes(t *testing.T) {
|
||||
require.Contains(t, schemes, "rtmp")
|
||||
require.Contains(t, schemes, "http")
|
||||
})
|
||||
|
||||
t.Run("non-GET requests return method not allowed", func(t *testing.T) {
|
||||
methods := []string{"POST", "PUT", "DELETE", "PATCH"}
|
||||
for _, method := range methods {
|
||||
t.Run(method, func(t *testing.T) {
|
||||
req := httptest.NewRequest(method, "/api/schemes", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
apiSchemes(w, req)
|
||||
|
||||
require.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestApiSchemesNoDuplicates(t *testing.T) {
|
||||
|
||||
@@ -2,9 +2,7 @@ package streams
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
@@ -18,15 +16,19 @@ func HandleFunc(scheme string, handler Handler) {
|
||||
handlers[scheme] = handler
|
||||
}
|
||||
|
||||
func GetSupportedSchemes() []string {
|
||||
unique := make(map[string]bool)
|
||||
func SupportedSchemes() []string {
|
||||
uniqueKeys := make(map[string]struct{}, len(handlers)+len(redirects))
|
||||
for scheme := range handlers {
|
||||
unique[scheme] = true
|
||||
uniqueKeys[scheme] = struct{}{}
|
||||
}
|
||||
for scheme := range redirects {
|
||||
unique[scheme] = true
|
||||
uniqueKeys[scheme] = struct{}{}
|
||||
}
|
||||
return slices.Collect(maps.Keys(unique))
|
||||
resultKeys := make([]string, 0, len(uniqueKeys))
|
||||
for key := range uniqueKeys {
|
||||
resultKeys = append(resultKeys, key)
|
||||
}
|
||||
return resultKeys
|
||||
}
|
||||
|
||||
func HasProducer(url string) bool {
|
||||
|
||||
Reference in New Issue
Block a user