blob: a052342ae87aacd1ed64a4b7268366b70571183e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package client
import (
"fmt"
"net/url"
"strings"
)
// 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
}
if u.Path != "" {
return "", fmt.Errorf("remote addresses should not have a path")
}
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
}
|