remoteutil: fix pkg remove unnecessary map initialization

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2024-07-15 13:36:28 -07:00
parent 85cf3bace9
commit 52bb668085
No known key found for this signature in database
GPG Key ID: AFA9DE5F8AB7AF39
4 changed files with 24 additions and 11 deletions

View File

@ -1,7 +1,7 @@
//go:build !windows
// +build !windows
package remote
package remoteutil
import (
"context"

View File

@ -1,4 +1,4 @@
package remote
package remoteutil
import (
"context"

View File

@ -1,18 +1,19 @@
package remote
package remoteutil
import (
"net/url"
"slices"
"github.com/pkg/errors"
)
var schemes = map[string]struct{}{
"tcp": {},
"unix": {},
"ssh": {},
"docker-container": {},
"kube-pod": {},
"npipe": {},
var schemes = []string{
"docker-container",
"kube-pod",
"npipe",
"ssh",
"tcp",
"unix",
}
func IsValidEndpoint(ep string) error {
@ -20,7 +21,7 @@ func IsValidEndpoint(ep string) error {
if err != nil {
return errors.Wrapf(err, "failed to parse endpoint %s", ep)
}
if _, ok := schemes[endpoint.Scheme]; !ok {
if _, ok := slices.BinarySearch(schemes, endpoint.Scheme); !ok {
return errors.Errorf("unrecognized url scheme %s", endpoint.Scheme)
}
return nil

View File

@ -0,0 +1,12 @@
package remoteutil
import (
"slices"
"testing"
"github.com/stretchr/testify/require"
)
func TestSchemes(t *testing.T) {
require.True(t, slices.IsSorted(schemes))
}