mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 20:27:03 +01:00
70ea2300ca
* Vendor: update gitea.com/macaron/session to a177a270 * make vendor * Vendor: update gitea.com/macaron/macaron to 0db5d458 * make vendor * Vendor: update gitea.com/macaron/cache to 905232fb * make vendor * Vendor: update gitea.com/macaron/i18n to 4ca3dd0c * make vendor * Vendor: update gitea.com/macaron/gzip to efa5e847 * make vendor * Vendor: update gitea.com/macaron/captcha to e8597820 * make vendor
49 lines
973 B
Go
Vendored
49 lines
973 B
Go
Vendored
package couchbase
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// CleanupHost returns the hostname with the given suffix removed.
|
|
func CleanupHost(h, commonSuffix string) string {
|
|
if strings.HasSuffix(h, commonSuffix) {
|
|
return h[:len(h)-len(commonSuffix)]
|
|
}
|
|
return h
|
|
}
|
|
|
|
// FindCommonSuffix returns the longest common suffix from the given
|
|
// strings.
|
|
func FindCommonSuffix(input []string) string {
|
|
rv := ""
|
|
if len(input) < 2 {
|
|
return ""
|
|
}
|
|
from := input
|
|
for i := len(input[0]); i > 0; i-- {
|
|
common := true
|
|
suffix := input[0][i:]
|
|
for _, s := range from {
|
|
if !strings.HasSuffix(s, suffix) {
|
|
common = false
|
|
break
|
|
}
|
|
}
|
|
if common {
|
|
rv = suffix
|
|
}
|
|
}
|
|
return rv
|
|
}
|
|
|
|
// ParseURL is a wrapper around url.Parse with some sanity-checking
|
|
func ParseURL(urlStr string) (result *url.URL, err error) {
|
|
result, err = url.Parse(urlStr)
|
|
if result != nil && result.Scheme == "" {
|
|
result = nil
|
|
err = fmt.Errorf("invalid URL <%s>", urlStr)
|
|
}
|
|
return
|
|
}
|