-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
58 lines (44 loc) · 871 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
58
package goadmin
import (
"context"
"fmt"
"strings"
"github.com/labstack/echo/v4"
)
func Path(paths ...string) string {
for i := range paths {
if i == 0 {
continue
}
paths[i] = strings.TrimLeft(paths[i], "/")
}
return strings.Join(paths, "/")
}
type AppContext struct {
echo.Context
app *App
}
func (c *AppContext) URL(path string, args ...interface{}) string {
result := Path(c.app.baseURL.Path, fmt.Sprintf(path, args...))
return result
}
func (c *AppContext) Data() *Data {
data, ok := c.Get(DataContextKey).(*Data)
if ok {
return data
}
return &Data{}
}
func (c *AppContext) User() *User {
user, ok := c.Get(UserContextKey).(*User)
if ok {
return user
}
return nil
}
func (c *AppContext) Ctx() context.Context {
return c.Request().Context()
}
func (c *AppContext) UserCase() UserUseCase {
return c.app.config.UserCase
}