aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common/common.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-16 01:00:13 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-16 01:00:13 +0200
commita8fd3fd6c8970bbf2d21e97c33fbb131f2fd4167 (patch)
tree7891a50fde70c1564758419d71c83180bd67e80e /clients/common/common.go
parentf7ec0637a509b063831d0f57e13840aff9a6d748 (diff)
downloadgo-git-a8fd3fd6c8970bbf2d21e97c33fbb131f2fd4167.tar.gz
clients/common: Endpoint SCP like support
Diffstat (limited to 'clients/common/common.go')
-rw-r--r--clients/common/common.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/clients/common/common.go b/clients/common/common.go
index c8dc7de..9099016 100644
--- a/clients/common/common.go
+++ b/clients/common/common.go
@@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"net/url"
+ "regexp"
"strings"
"gopkg.in/src-d/go-git.v4/core"
@@ -36,7 +37,14 @@ type AuthMethod interface {
type Endpoint url.URL
+var (
+ isSchemeRegExp = regexp.MustCompile("^[^:]+://")
+ scpLikeUrlRegExp = regexp.MustCompile("^(?P<user>[^@]+@)?(?P<host>[^:]+):/?(?P<path>.+)$")
+)
+
func NewEndpoint(endpoint string) (Endpoint, error) {
+ endpoint = transformSCPLikeIfNeeded(endpoint)
+
u, err := url.Parse(endpoint)
if err != nil {
return Endpoint{}, core.NewPermanentError(err)
@@ -51,6 +59,15 @@ func NewEndpoint(endpoint string) (Endpoint, error) {
return Endpoint(*u), nil
}
+func transformSCPLikeIfNeeded(endpoint string) string {
+ if !isSchemeRegExp.MatchString(endpoint) && scpLikeUrlRegExp.MatchString(endpoint) {
+ m := scpLikeUrlRegExp.FindStringSubmatch(endpoint)
+ return fmt.Sprintf("ssh://%s%s/%s", m[1], m[2], m[3])
+ }
+
+ return endpoint
+}
+
func (e *Endpoint) String() string {
u := url.URL(*e)
return u.String()