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