From 447509b313b71bd222281d095d1579b44525473c Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Thu, 21 May 2015 22:20:25 +0200 Subject: [PATCH] Add syslog-address log-opt Signed-off-by: Antonio Murdaca --- urlutil/url.go | 19 ------------- urlutil/{git.go => urlutil.go} | 35 ++++++++++++++++-------- urlutil/{git_test.go => urlutil_test.go} | 0 3 files changed, 24 insertions(+), 30 deletions(-) delete mode 100644 urlutil/url.go rename urlutil/{git.go => urlutil.go} (53%) rename urlutil/{git_test.go => urlutil_test.go} (100%) diff --git a/urlutil/url.go b/urlutil/url.go deleted file mode 100644 index eeae56e..0000000 --- a/urlutil/url.go +++ /dev/null @@ -1,19 +0,0 @@ -package urlutil - -import "strings" - -var validUrlPrefixes = []string{ - "http://", - "https://", -} - -// IsURL returns true if the provided str is a valid URL by doing -// a simple change for the transport of the url. -func IsURL(str string) bool { - for _, prefix := range validUrlPrefixes { - if strings.HasPrefix(str, prefix) { - return true - } - } - return false -} diff --git a/urlutil/git.go b/urlutil/urlutil.go similarity index 53% rename from urlutil/git.go rename to urlutil/urlutil.go index dc4d666..7250643 100644 --- a/urlutil/git.go +++ b/urlutil/urlutil.go @@ -6,26 +6,25 @@ import ( ) var ( - validPrefixes = []string{ - "git://", - "github.com/", - "git@", + validPrefixes = map[string][]string{ + "url": {"http://", "https://"}, + "git": {"git://", "github.com/", "git@"}, + "transport": {"tcp://", "udp://", "unix://"}, } - urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$") ) +// IsURL returns true if the provided str is an HTTP(S) URL. +func IsURL(str string) bool { + return checkURL(str, "url") +} + // IsGitURL returns true if the provided str is a git repository URL. func IsGitURL(str string) bool { if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) { return true } - for _, prefix := range validPrefixes { - if strings.HasPrefix(str, prefix) { - return true - } - } - return false + return checkURL(str, "git") } // IsGitTransport returns true if the provided str is a git transport by inspecting @@ -33,3 +32,17 @@ func IsGitURL(str string) bool { func IsGitTransport(str string) bool { return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") } + +// IsTransportURL returns true if the provided str is a transport (tcp, udp, unix) URL. +func IsTransportURL(str string) bool { + return checkURL(str, "transport") +} + +func checkURL(str, kind string) bool { + for _, prefix := range validPrefixes[kind] { + if strings.HasPrefix(str, prefix) { + return true + } + } + return false +} diff --git a/urlutil/git_test.go b/urlutil/urlutil_test.go similarity index 100% rename from urlutil/git_test.go rename to urlutil/urlutil_test.go