From 48a77ea54cd7bc32f2ca4f70609ef06524d06707 Mon Sep 17 00:00:00 2001 From: KArtHiK Date: Mon, 16 Feb 2026 09:40:35 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A5Few=20code=20cleanups=20and=20organ?= =?UTF-8?q?ising?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/components/vapplication/list.templ | 10 ++------ app/web/views/components/vfavorite/list.templ | 10 ++------ helpers/url.go | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/web/views/components/vapplication/list.templ b/app/web/views/components/vapplication/list.templ index 66a3df2..67ad3c3 100644 --- a/app/web/views/components/vapplication/list.templ +++ b/app/web/views/components/vapplication/list.templ @@ -5,16 +5,10 @@ import ( "github.com/cloudness-io/cloudness/app/utils/routes" "github.com/cloudness-io/cloudness/app/web/views/components/icons" "github.com/cloudness-io/cloudness/app/web/views/shared" + "github.com/cloudness-io/cloudness/helpers" "github.com/cloudness-io/cloudness/types" - "strings" ) -func trimProtocol(url string) string { - url = strings.TrimPrefix(url, "https://") - url = strings.TrimPrefix(url, "http://") - return strings.TrimSuffix(url, "/") -} - templ appHeaderDescription(env *types.Environment) { You are viewing applications in { env.Name } Environment @@ -50,7 +44,7 @@ templ list(env *types.Environment, apps []*types.Application) { if app.Domain != "" { - { trimProtocol(app.Domain) } + { helpers.TrimProtocol(app.Domain) } @shared.Icon(icons.OutIcon, "size-3 shrink-0") } diff --git a/app/web/views/components/vfavorite/list.templ b/app/web/views/components/vfavorite/list.templ index 86d47cf..58f0430 100644 --- a/app/web/views/components/vfavorite/list.templ +++ b/app/web/views/components/vfavorite/list.templ @@ -3,8 +3,8 @@ package vfavorite import "github.com/cloudness-io/cloudness/types" import "github.com/cloudness-io/cloudness/app/web/views/shared" import "github.com/cloudness-io/cloudness/app/utils/routes" -import "strings" import "github.com/cloudness-io/cloudness/app/web/views/components/icons" +import "github.com/cloudness-io/cloudness/helpers" templ ListPlaceholder(tenant *types.Tenant) { @shared.PageSection("Favorites", templ.NopComponent, templ.NopComponent) { @@ -46,7 +46,7 @@ templ List(favs []*types.FavoriteDTO) { if fav.AppDomain != "" { - { trimProtocol(fav.AppDomain) } + { helpers.TrimProtocol(fav.AppDomain) } @shared.Icon(icons.OutIcon, "size-3 shrink-0") } @@ -59,9 +59,3 @@ templ List(favs []*types.FavoriteDTO) { } } - -func trimProtocol(url string) string { - url = strings.TrimPrefix(url, "https://") - url = strings.TrimPrefix(url, "http://") - return strings.TrimSuffix(url, "/") -} diff --git a/helpers/url.go b/helpers/url.go index df5e90a..808c978 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -31,3 +31,26 @@ func ParseFQDN(fqdn string) (scheme string, subdomain string, domain string) { func GenerateFQDN(schema string, subdomain string, domain string) string { return schema + "://" + subdomain + "." + domain } + +// TrimProtocol removes http/https prefixes and any trailing slashes, preserving host and path. +func TrimProtocol(raw string) string { + trimmed := strings.TrimSpace(raw) + if trimmed == "" { + return "" + } + + lower := strings.ToLower(trimmed) + switch { + case strings.HasPrefix(lower, "https://"): + trimmed = trimmed[len("https://"):] + case strings.HasPrefix(lower, "http://"): + trimmed = trimmed[len("http://"):] + default: + if u, err := url.Parse(trimmed); err == nil && u.Scheme != "" { + // Fallback for other schemes (keeps host/path, drops scheme) + trimmed = strings.TrimPrefix(trimmed, u.Scheme+"://") + } + } + + return strings.TrimRight(trimmed, "/") +}