Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'client/address_parser.go')
-rw-r--r--client/address_parser.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/client/address_parser.go b/client/address_parser.go
index 55969e909..a052342ae 100644
--- a/client/address_parser.go
+++ b/client/address_parser.go
@@ -3,22 +3,36 @@ package client
import (
"fmt"
"net/url"
+ "strings"
)
-func parseAddress(rawAddress string) (canonicalAddress string, err error) {
+// extractHostFromRemoteURL will convert Gitaly-style URL addresses of the form
+// scheme://host:port to the "host:port" addresses used by `grpc.Dial`
+func extractHostFromRemoteURL(rawAddress string) (hostAndPort string, err error) {
u, err := url.Parse(rawAddress)
if err != nil {
return "", err
}
- // tcp:// addresses are a special case which `grpc.Dial` expects in a
- // different format
- if u.Scheme == "tcp" || u.Scheme == "tls" {
- if u.Path != "" {
- return "", fmt.Errorf("%s addresses should not have a path", u.Scheme)
- }
- return u.Host, nil
+ if u.Path != "" {
+ return "", fmt.Errorf("remote addresses should not have a path")
}
- return u.String(), nil
+ if u.Host == "" {
+ return "", fmt.Errorf("remote addresses should have a host")
+ }
+
+ return u.Host, nil
+}
+
+// extractPathFromSocketURL will convert Gitaly-style URL addresses of the form
+// unix:/path/to/socket into file paths: `/path/to/socket`
+const unixPrefix = "unix:"
+
+func extractPathFromSocketURL(rawAddress string) (socketPath string, err error) {
+ if !strings.HasPrefix(rawAddress, unixPrefix) {
+ return "", fmt.Errorf("invalid socket address: %s", rawAddress)
+ }
+
+ return strings.TrimPrefix(rawAddress, unixPrefix), nil
}