-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
63 lines (55 loc) · 1.4 KB
/
index.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
59
60
61
62
63
package index
import (
"time"
"github.com/webx-top/echo"
"github.com/webx-top/echo/code"
"github.com/admpub/nging/v5/application/library/codec"
"github.com/admpub/nging/v5/application/library/config"
"github.com/admpub/webx/application/handler/frontend/article"
)
var (
// UnimplementedHandler 默认未实现处理
UnimplementedHandler = func(c echo.Context) error {
return c.String(`Unimplemented`)
}
// DefaultIndexHandler 默认首页处理
DefaultIndexHandler = article.List
// DefaultSearchHandler 默认搜索处理
DefaultSearchHandler = UnimplementedHandler
)
func Index(c echo.Context) error {
defaultHandler := config.Setting(`base`).String(`defaultHandler`)
if len(defaultHandler) > 0 && defaultHandler != c.Path() {
return c.Dispatch(defaultHandler).Handle(c)
}
return DefaultIndexHandler(c)
}
func Search(c echo.Context) error {
return DefaultSearchHandler(c)
}
func ErrorCode(c echo.Context) error {
data := c.Data()
sortBy := c.Form("sortBy")
if sortBy == `code` {
data.SetData(code.CodeDict)
} else {
result := map[string]code.Code{}
for n, v := range code.CodeDict {
result[v.Text] = n
}
data.SetData(result)
}
return c.JSON(data)
}
func SecureKey(c echo.Context) error {
ip := c.RealIP()
ts := time.Now().Unix()
sm2Pubkey := codec.DefaultPublicKeyHex()
data := c.Data()
data.SetData(echo.H{
`ip`: ip,
`ts`: ts,
`key`: sm2Pubkey,
})
return c.JSON(data)
}