-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
57 lines (43 loc) · 833 Bytes
/
context.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
48
49
50
51
52
53
54
55
56
57
package goadmin
import (
"context"
"strings"
"github.com/labstack/echo/v4"
)
type AdminContext struct {
echo.Context
admin *Admin
}
func (c AdminContext) URL(path string) string {
result := Path(c.admin.baseURL.Path, path)
return result
}
func (c *AdminContext) Data() *Data {
data, ok := c.Get(DataContextKey).(*Data)
if ok {
return data
}
return &Data{}
}
func (c *AdminContext) User() *User {
user, ok := c.Get(UserContextKey).(*User)
if ok {
return user
}
return nil
}
func (c *AdminContext) Ctx() context.Context {
return c.Request().Context()
}
func (c *AdminContext) UserCase() UserUseCase {
return c.admin.UserCase
}
func Path(paths ...string) string {
for i := range paths {
if i == 0 {
continue
}
paths[i] = strings.TrimLeft(paths[i], "/")
}
return strings.Join(paths, "/")
}