2022-07-08 08:26:13 +00:00
|
|
|
package utils
|
|
|
|
|
2023-05-29 05:38:13 +00:00
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
|
|
|
)
|
2022-07-08 08:26:13 +00:00
|
|
|
|
|
|
|
const prefix = "/vmalert/"
|
|
|
|
|
2022-07-08 10:25:23 +00:00
|
|
|
// Prefix returns "/vmalert/" prefix if it is missing in the path.
|
2022-07-08 08:26:13 +00:00
|
|
|
func Prefix(path string) string {
|
2023-05-29 05:38:13 +00:00
|
|
|
pp := httpserver.GetPathPrefix()
|
|
|
|
path = strings.TrimLeft(path, pp)
|
2022-07-08 08:26:13 +00:00
|
|
|
if strings.HasPrefix(path, prefix) {
|
2023-05-29 05:38:13 +00:00
|
|
|
return pp
|
|
|
|
}
|
|
|
|
res, err := url.JoinPath(pp, prefix)
|
|
|
|
if err != nil {
|
|
|
|
return path
|
2022-07-08 08:26:13 +00:00
|
|
|
}
|
2023-05-29 05:38:13 +00:00
|
|
|
return res
|
2022-07-08 08:26:13 +00:00
|
|
|
}
|