buildx/driver/remote/util/endpoint.go
Tonis Tiigi 52bb668085
remoteutil: fix pkg remove unnecessary map initialization
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-15 16:39:58 -07:00

29 lines
482 B
Go

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