-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathroot.go
More file actions
40 lines (33 loc) · 727 Bytes
/
root.go
File metadata and controls
40 lines (33 loc) · 727 Bytes
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
package root
import (
"github.com/GoAdminGroup/go-admin/context"
errors "github.com/GoAdminGroup/librarian/modules/error"
)
type Root struct {
Path string
Title string
}
type Roots map[string]Root
func (r Roots) Add(key string, value Root) {
r[key] = value
}
func (r Roots) GetPathFromPrefix(ctx *context.Context) string {
return r.GetFromPrefix(ctx).Path
}
func (r Roots) GetTitleFromPrefix(ctx *context.Context) string {
return r.GetFromPrefix(ctx).Title
}
func (r Roots) GetFromPrefix(ctx *context.Context) Root {
prefix := ctx.Query("__prefix")
if prefix == "" {
if len(r) != 0 {
for _, v := range r {
return v
}
}
}
if rr, ok := r[prefix]; ok {
return rr
}
panic(errors.WrongPrefix)
}