// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). You may // not use this file except in compliance with the License. A copy of the // License is located at // // http://aws.amazon.com/apache2.0/ // // or in the "license" file accompanying this file. This file is distributed // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either // express or implied. See the License for the specific language governing // permissions and limitations under the License. package util import ( "fmt" "net/url" "os" "path/filepath" "strings" ) func ParseEndpoint(endpoint string) (string, string, error) { u, err := url.Parse(endpoint) if err != nil { return "", "", fmt.Errorf("could not parse endpoint: %w", err) } addr := filepath.Join(u.Host, filepath.FromSlash(u.Path)) scheme := strings.ToLower(u.Scheme) switch scheme { case "tcp": case "unix": addr = filepath.Join("/", addr) if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { return "", "", fmt.Errorf("could not remove unix domain socket %q: %w", addr, err) } default: return "", "", fmt.Errorf("unsupported protocol: %s", scheme) } return scheme, addr, nil }