diff options
Diffstat (limited to 'modules/util/util.go')
-rw-r--r-- | modules/util/util.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/util/util.go b/modules/util/util.go index e99f951f21..3a0411f64b 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -4,6 +4,13 @@ package util +import ( + "net/url" + "path" + + "code.gitea.io/gitea/modules/log" +) + // OptionalBool a boolean that can be "null" type OptionalBool byte @@ -47,6 +54,20 @@ func Max(a, b int) int { return a } +// URLJoin joins url components, like path.Join, but preserving contents +func URLJoin(base string, elems ...string) string { + u, err := url.Parse(base) + if err != nil { + log.Error(4, "URLJoin: Invalid base URL %s", base) + return "" + } + joinArgs := make([]string, 0, len(elems)+1) + joinArgs = append(joinArgs, u.Path) + joinArgs = append(joinArgs, elems...) + u.Path = path.Join(joinArgs...) + return u.String() +} + // Min min of two ints func Min(a, b int) int { if a > b { |