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 //go:build !windows
// +build !windows // +build !windows
package remote package remoteutil
import ( import (
"context" "context"

View File

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

View File

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