From b899e60d5c5004525d9a554d1d5074d062c3fb95 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 7 Apr 2025 16:41:09 +0200 Subject: pkg/html: split off URL helpers The existing pkg/html package transitively takes too many dependencies, which complicates the reuse of some of its methods. Split off a pkg/html/urlutil package. --- pkg/html/html.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) (limited to 'pkg/html/html.go') diff --git a/pkg/html/html.go b/pkg/html/html.go index 4893b8377..9d15c8777 100644 --- a/pkg/html/html.go +++ b/pkg/html/html.go @@ -6,7 +6,6 @@ package html import ( "fmt" "html/template" - "net/url" "path/filepath" "reflect" "strings" @@ -214,46 +213,3 @@ func dereferencePointer(v interface{}) interface{} { func commitLink(repo, commit string) string { return vcs.CommitLink(repo, commit) } - -func AmendURL(baseURL, key, value string) string { - return TransformURL(baseURL, key, func(_ []string) []string { - if value == "" { - return nil - } - return []string{value} - }) -} - -func DropParam(baseURL, key, value string) string { - return TransformURL(baseURL, key, func(oldValues []string) []string { - if value == "" { - return nil - } - var newValues []string - for _, iterVal := range oldValues { - if iterVal != value { - newValues = append(newValues, iterVal) - } - } - return newValues - }) -} - -func TransformURL(baseURL, key string, f func([]string) []string) string { - if baseURL == "" { - return "" - } - parsed, err := url.Parse(baseURL) - if err != nil { - return "" - } - values := parsed.Query() - ret := f(values[key]) - if len(ret) == 0 { - values.Del(key) - } else { - values[key] = ret - } - parsed.RawQuery = values.Encode() - return parsed.String() -} -- cgit mrf-deployment