The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/services/store/utils.go

48 lines
875 B

package store
import (
"strings"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/web"
)
func GuessNameFromUID(uid string) string {
sidx := strings.LastIndex(uid, "/") + 1
didx := strings.LastIndex(uid, ".")
if didx > sidx && didx != sidx {
return uid[sidx:didx]
}
if sidx > 0 {
return uid[sidx:]
}
return uid
}
func splitFirstSegment(path string) (string, string) {
idx := strings.Index(path, "/")
if idx == 0 {
path = path[1:]
idx = strings.Index(path, "/")
}
if idx > 0 {
return path[:idx], path[idx+1:]
}
return path, ""
}
func getPathAndScope(c *models.ReqContext) (string, string) {
params := web.Params(c.Req)
path := params["*"]
if path == "" {
return "", ""
}
return splitFirstSegment(path)
}
func getFirstSegment(path string) string {
firstSegment, _ := splitFirstSegment(path)
return firstSegment
}