Merge pull request #13392 from runcom/syslog-connection-url-log-opt
Add syslog-address log-opt
This commit is contained in:
commit
0381b5ceb9
3 changed files with 24 additions and 30 deletions
|
@ -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
|
|
||||||
}
|
|
|
@ -6,26 +6,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
validPrefixes = []string{
|
validPrefixes = map[string][]string{
|
||||||
"git://",
|
"url": {"http://", "https://"},
|
||||||
"github.com/",
|
"git": {"git://", "github.com/", "git@"},
|
||||||
"git@",
|
"transport": {"tcp://", "udp://", "unix://"},
|
||||||
}
|
}
|
||||||
|
|
||||||
urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
|
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.
|
// IsGitURL returns true if the provided str is a git repository URL.
|
||||||
func IsGitURL(str string) bool {
|
func IsGitURL(str string) bool {
|
||||||
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
|
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, prefix := range validPrefixes {
|
return checkURL(str, "git")
|
||||||
if strings.HasPrefix(str, prefix) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsGitTransport returns true if the provided str is a git transport by inspecting
|
// 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 {
|
func IsGitTransport(str string) bool {
|
||||||
return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue