1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00
gocsaf/util/url.go
Sascha L. Teichmann b359fd0a62
Add CSAF downloader
* Dense and refactor ROLIE code in aggregator a bit.
* Move  advisory file processor to csaf package.
* Fix minor typo on main readme
2022-06-23 14:14:44 +02:00

30 lines
745 B
Go

// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2022 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2022 Intevation GmbH <https://intevation.de>
package util
import (
"net/url"
"strings"
)
// BaseURL returns the base URL for a given URL.
func BaseURL(u *url.URL) (string, error) {
ep := u.EscapedPath()
if idx := strings.LastIndexByte(ep, '/'); idx != -1 {
ep = ep[:idx+1]
}
user := u.User.String()
if user != "" {
user += "@"
}
if !strings.HasPrefix(ep, "/") {
ep = "/" + ep
}
return u.Scheme + "://" + user + u.Host + ep, nil
}