Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/host/host.go')
-rw-r--r--internal/host/host.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/host/host.go b/internal/host/host.go
new file mode 100644
index 00000000..dd9b1c8a
--- /dev/null
+++ b/internal/host/host.go
@@ -0,0 +1,23 @@
+package host
+
+import (
+ "net"
+ "net/http"
+ "strings"
+)
+
+// FromString tries to split host port from string, returns host or initial string if fail
+func FromString(s string) string {
+ host := strings.ToLower(s)
+
+ if splitHost, _, err := net.SplitHostPort(host); err == nil {
+ host = splitHost
+ }
+
+ return host
+}
+
+// FromRequest tries to split host port from r.Host, returns host or initial string if fail
+func FromRequest(r *http.Request) string {
+ return FromString(r.Host)
+}