forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
47 lines (40 loc) · 917 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package store
import (
"strings"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"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 *contextmodel.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
}